X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=encoding.c;h=7789cfce718f90f5abb2463c05b77a3f0089e1e0;hb=b3de45c3f2fccd3942dcae999c96aa1026d21d91;hp=bd33b87b63ae096e69d5ac92d40c1f3266ac903e;hpb=d2233f145e24a310889e4cc650365077786da3d9;p=gedcom-parse.git diff --git a/encoding.c b/encoding.c index bd33b87..7789cfc 100644 --- a/encoding.c +++ b/encoding.c @@ -22,7 +22,6 @@ #define MAXBUF 255 static iconv_t cd_to_internal = (iconv_t) -1; -static char int_buf[MAXGEDCLINELEN*2]; static void *encoding_mapping = NULL; static ENCODING the_enc = ONE_BYTE; @@ -114,7 +113,7 @@ void set_encoding_width(ENCODING enc) } static char conv_buf[MAXGEDCLINELEN * 2]; -static int conv_buf_size; +static size_t conv_buf_size; int open_conv_to_internal(char* fromcode) { @@ -142,25 +141,22 @@ void close_conv_to_internal() cd_to_internal = (iconv_t) -1; } -char* to_internal(char* str, size_t len) +char* to_internal(char* str, size_t len, + char* output_buffer, size_t out_len) { - size_t insize; - size_t outsize = MAXGEDCLINELEN * 2; - char *wrptr = int_buf; + size_t outsize = out_len; + char *wrptr = output_buffer; char *rdptr = conv_buf; /* set up input buffer (concatenate to what was left previous time) */ /* can't use strcpy, because possible null bytes from unicode */ memcpy(conv_buf + conv_buf_size, str, len); conv_buf_size += len; - insize = conv_buf_size; /* set up output buffer (empty it) */ - memset(int_buf, 0, sizeof(int_buf)); + memset(output_buffer, 0, out_len); /* do the conversion */ - iconv(cd_to_internal, &rdptr, &insize, &wrptr, &outsize); + iconv(cd_to_internal, &rdptr, &conv_buf_size, &wrptr, &outsize); /* then shift what is left over to the head of the input buffer */ - memmove(conv_buf, rdptr, insize); - memset(conv_buf + insize, 0, sizeof(conv_buf) - insize); - conv_buf_size = insize; - return int_buf; + memmove(conv_buf, rdptr, conv_buf_size); + memset(conv_buf + conv_buf_size, 0, sizeof(conv_buf) - conv_buf_size); + return output_buffer; } -