X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=utf8%2Futf8-locale.c;h=9d58b625db3c47eae95f13604e682502c26dcd71;hb=80b0ecad6b60c69b8bef41b85e4e53fe37364d55;hp=1b3e255cc6fb062ca0d9b69ed51f3446d3cc5025;hpb=a989ed6b8feb891cbd7ef99eec26cdb65c6e442e;p=gedcom-parse.git diff --git a/utf8/utf8-locale.c b/utf8/utf8-locale.c index 1b3e255..9d58b62 100644 --- a/utf8/utf8-locale.c +++ b/utf8/utf8-locale.c @@ -11,10 +11,11 @@ #include #include -#include #include #include +#include #include "config.h" +#include "libcharset.h" #include "utf8-locale.h" #define INITIAL_OUTSIZE 256 @@ -43,11 +44,11 @@ int open_conversion_contexts() { 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; @@ -69,8 +70,10 @@ char* convert_utf8_to_locale(const char* input, int *conv_fails) 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); @@ -112,6 +115,7 @@ char* convert_utf8_to_locale(const char* input, int *conv_fails) 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);