Skip to Content.
Sympa Menu

freetds - Re: [freetds] pbcb: replacing strcpy(3)

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddyz77 AT tin.it>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] pbcb: replacing strcpy(3)
  • Date: Thu, 08 May 2003 06:22:44 -0000

Il gio, 2003-05-08 alle 06:51, James K.Lowden ha scritto:
> Many of the fixme comments to do with iconv regard the "length * 2"
> assumption and request, correctly, that iconv be used instead. That is
> part of the generalization toward UTF-8 servers and/or clients.
>
> I intend to leverage the TDS_PBCB struct I introduced in bcp.c, adding a
> "size" member:
>
> typedef struct _pbcb
> {
> unsigned char *pb; /* buffer ("pointer to bytes")*/
> unsigned int cb; /* count of bytes of data */
> unsigned int size; /* size of allocation */
> } TDS_PBCB;
>
> These are of course counted strings. I'm planning a family of strcpy-like
> functions:
>
> /* allocation */
> TDS_PBCB* pbcb_alloc (TDS_PBCB* pbcb, int size);
> void pbcb_free(TDS_PBCB*); /* frees pointer and reinitializes */
> TDS_PBCB* pbcb_strdup (iconv_t cd, TDS_PBCB* pbcb, const char *s);
>
> /* copy */
> TDS_PBCB* pbcb_cpy (iconv_t cd, TDS_PBCB* dest, const TDS_PBCB* src);
> TDS_PBCB* pbcb_strcpy (iconv_t cd, TDS_PBCB* pbcb, const char *src);
>
> These would become the standard replacements for string buffer handling in
> FreeTDS.
>
> If you have a better idea or intensely dislike this one, please speak up.
>
>
> My one concern is that there's no way to know the encoding of the buffer.
> Unfortunately, neither is there any way to *extract* the encoding from an
> iconv_t, nor do we have an enumerated set of encodings. (I suspect this
> is one reason Win32 and OS X both use integers, rather than strings, to
> identify encodings. Much simpler to pass around and compare.)
>

James, dstr_* was designed to be extended in such way...

TDS_PBCB* pbcb_cpy (iconv_t cd, TDS_PBCB* dest, const TDS_PBCB* src);
TDS_PBCB* pbcb_strcpy (iconv_t cd, TDS_PBCB* pbcb, const char *src);

Why pass iconv_t just to copy a buffer?
All I need (in query.c) is a function to return byte count of converted
string... Something like tds_get_converted_length(TDSICONVINFO * ic,
const char* s, size_t length);

freddy77






Archive powered by MHonArc 2.6.24.

Top of Page