Updates for string and UTF-8 functions.
[gedcom-parse.git] / utf8 / utf8-locale.c
index 6db205bd762778d4c1f3ea0c00db957ca35f82e6..28eeb4b24c8c1b7806c2b2a258f748fc7c9c6aad 100644 (file)
@@ -16,7 +16,7 @@
 #include <string.h>
 #include "config.h"
 #include "libcharset.h"
-#include "utf8-locale.h"
+#include "utf8.h"
 
 #define INITIAL_OUTSIZE 256
 
@@ -70,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);
@@ -113,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);