From: Peter Verthez Date: Sun, 1 Dec 2002 15:25:20 +0000 (+0000) Subject: Extra arguments for the length of non-UTF-8 strings. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=4c5bbb2dff95ecfd854f47af33e3e05d59bae3b5;p=gedcom-parse.git Extra arguments for the length of non-UTF-8 strings. --- diff --git a/utf8/utf8-convert.c b/utf8/utf8-convert.c index 097f199..926e14c 100644 --- a/utf8/utf8-convert.c +++ b/utf8/utf8-convert.c @@ -187,7 +187,8 @@ void cleanup_utf8_conversion(convert_t conv) } } -char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails) +char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails, + size_t* output_len) { size_t insize = strlen(input); size_t outsize; @@ -246,12 +247,12 @@ char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails) } nconv = iconv(conv->from_utf8, &inptr, &insize, &outptr, &outsize); } + if (output_len) *output_len = outptr - outbuf->buffer; return outbuf->buffer; } -char* convert_to_utf8(convert_t conv, const char* input) +char* convert_to_utf8(convert_t conv, const char* input, size_t input_len) { - size_t insize = strlen(input); size_t outsize; ICONV_CONST char *inptr = (ICONV_CONST char*) input; char *outptr; @@ -267,7 +268,7 @@ char* convert_to_utf8(convert_t conv, const char* input) outptr = outbuf->buffer; outsize = outbuf->size; reset_conv_buffer(conv->outbuf); - nconv = iconv(conv->to_utf8, &inptr, &insize, &outptr, &outsize); + nconv = iconv(conv->to_utf8, &inptr, &input_len, &outptr, &outsize); while (nconv == (size_t)-1) { if (errno == E2BIG) { /* grow the output buffer */ @@ -286,7 +287,7 @@ char* convert_to_utf8(convert_t conv, const char* input) /* EBADF is an error which should be captured by the first if above */ return NULL; } - nconv = iconv(conv->to_utf8, &inptr, &insize, &outptr, &outsize); + nconv = iconv(conv->to_utf8, &inptr, &input_len, &outptr, &outsize); } return outbuf->buffer; } diff --git a/utf8/utf8-locale.c b/utf8/utf8-locale.c index 9ede577..a59b8ce 100644 --- a/utf8/utf8-locale.c +++ b/utf8/utf8-locale.c @@ -12,6 +12,7 @@ #include "utf8.h" #include #include +#include #include "libcharset.h" static convert_t locale_conv = NULL; @@ -47,7 +48,7 @@ char* convert_utf8_to_locale(const char* input, int *conv_fails) if (!locale_conv) open_conversion_contexts(); - return convert_from_utf8(locale_conv, input, conv_fails); + return convert_from_utf8(locale_conv, input, conv_fails, NULL); } char* convert_locale_to_utf8(const char* input) @@ -55,5 +56,5 @@ char* convert_locale_to_utf8(const char* input) if (!locale_conv) open_conversion_contexts(); - return convert_to_utf8(locale_conv, input); + return convert_to_utf8(locale_conv, input, strlen(input)); } diff --git a/utf8/utf8.h b/utf8/utf8.h index 131dfbc..3cfb1c1 100644 --- a/utf8/utf8.h +++ b/utf8/utf8.h @@ -41,8 +41,9 @@ convert_t initialize_utf8_conversion(const char* charset, int external_outbuf); int conversion_set_unknown(convert_t conv, const char* unknown); int conversion_set_output_buffer(convert_t conv, conv_buffer_t buf); void cleanup_utf8_conversion(convert_t conv); -char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails); -char* convert_to_utf8(convert_t conv, const char* input); +char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails, + size_t* output_len); +char* convert_to_utf8(convert_t conv, const char* input, size_t input_len); char* convert_to_utf8_incremental(convert_t conv, const char* input, size_t input_len);