}
}
-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;
}
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;
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 */
/* 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;
}
#include "utf8.h"
#include <stdlib.h>
#include <assert.h>
+#include <string.h>
#include "libcharset.h"
static convert_t locale_conv = NULL;
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)
if (!locale_conv)
open_conversion_contexts();
- return convert_to_utf8(locale_conv, input);
+ return convert_to_utf8(locale_conv, input, strlen(input));
}
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);