summaryrefslogtreecommitdiff
path: root/lib/util/charset
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util/charset')
-rw-r--r--lib/util/charset/iconv.c6
-rw-r--r--lib/util/charset/wscript_configure20
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/util/charset/iconv.c b/lib/util/charset/iconv.c
index bf561f26619..e06fa2ca396 100644
--- a/lib/util/charset/iconv.c
+++ b/lib/util/charset/iconv.c
@@ -740,12 +740,12 @@ static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft,
}
if ((uc[1] & 0xfc) == 0xdc) {
- /* its the second part of a 4 byte sequence. Illegal */
+ errno = EILSEQ;
+#ifndef HAVE_ICONV_ERRNO_ILLEGAL_MULTIBYTE
if (in_left < 4) {
errno = EINVAL;
- } else {
- errno = EILSEQ;
}
+#endif
goto error;
}
diff --git a/lib/util/charset/wscript_configure b/lib/util/charset/wscript_configure
index 804c2663f64..d5ac5d0100f 100644
--- a/lib/util/charset/wscript_configure
+++ b/lib/util/charset/wscript_configure
@@ -16,3 +16,23 @@ if (conf.CHECK_FUNCS_IN('iconv_open', 'iconv', checklibc=False, headers='iconv.h
conf.CHECK_FUNCS('iconv_open', headers='iconv.h')):
conf.DEFINE('HAVE_NATIVE_ICONV', 1)
+
+conf.CHECK_CODE('''
+ uint8_t inbuf[2] = { 0x30, 0xdf };
+ uint8_t outbuf[4] = { 0 };
+ char *ptr_in = (char *)inbuf;
+ char *ptr_out = (char *)outbuf;
+ size_t size_in = sizeof(inbuf);
+ size_t size_out = sizeof(outbuf);
+ size_t ret;
+ iconv_t cd;
+ cd = iconv_open("UTF-8", "UTF-16LE");
+ if (cd == 0 || cd == (iconv_t)-1) return -1;
+ ret = iconv(cd, &ptr_in, &size_in, &ptr_out, &size_out);
+ if (ret != (size_t)-1 || errno != EILSEQ) return -1;
+ ''',
+ define='HAVE_ICONV_ERRNO_ILLEGAL_MULTIBYTE',
+ execute=True,
+ msg='Checking errno of iconv for illegal multibyte sequence',
+ lib='iconv',
+ headers='errno.h iconv.h')