[freetds] pbcb: replacing strcpy(3)

James K.Lowden jklowden at speakeasy.net
Thu May 8 00:51:02 EDT 2003

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 */

These are of course counted strings.  I'm planning a family of strcpy-like

/* 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

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.)  


More information about the FreeTDS mailing list