#include <stdlib.h>
#include <iconv.h>
-#include <langinfo.h>
#include <assert.h>
#include <errno.h>
+#include <string.h>
#include "config.h"
+#include "libcharset.h"
#include "utf8-locale.h"
#define INITIAL_OUTSIZE 256
{
assert(utf8_to_locale == (iconv_t) -1);
assert(locale_to_utf8 == (iconv_t) -1);
- utf8_to_locale = iconv_open(nl_langinfo(CODESET), "UTF-8");
+ utf8_to_locale = iconv_open(locale_charset(), "UTF-8");
if (utf8_to_locale == (iconv_t) -1)
return -1;
else {
- locale_to_utf8 = iconv_open("UTF-8", nl_langinfo(CODESET));
+ locale_to_utf8 = iconv_open("UTF-8", locale_charset());
if (locale_to_utf8 == (iconv_t) -1) {
close_conversion_contexts();
return -1;
char *outptr;
size_t nconv;
- if (utf8_to_locale == (iconv_t) -1 && (open_conversion_contexts() == -1))
+ if (utf8_to_locale == (iconv_t) -1 && (open_conversion_contexts() == -1)) {
+ if (conv_fails != NULL) *conv_fails = insize;
return NULL;
+ }
assert(utf8_to_locale != (iconv_t) -1);
/* make sure we start from an empty state */
iconv(utf8_to_locale, NULL, NULL, NULL, NULL);
else {
/* EINVAL should not happen, since we convert entire strings */
/* EBADF is an error which should be captured by the assert above */
+ if (conv_fails != NULL) *conv_fails += insize;
return NULL;
}
nconv = iconv(utf8_to_locale, &inptr, &insize, &outptr, &outsize);