Date: Sun, 11 Sep 2011 17:38:44 -0700 From: Tim Kientzle <kientzle@freebsd.org> To: FreeBSD-current Current <freebsd-current@freebsd.org> Subject: iconv not reporting errors? Message-ID: <F485CB54-88C7-4D5A-B3E8-AC5CF6DF226B@freebsd.org>
index | next in thread | raw e-mail
I'm trying to use the iconv that's in FreeBSD-CURRENT and it's not reporting errors the way I expect. To demonstrate, here's a test program that tries to convert UTF-8 to KOI8-R. This should report an error, since the UTF-8 string here "ĐÒÉ×ÅÔ" contains characters not available in KOI8-R. On FreeBSD-CURRENT (updated yesterday), the iconv() call returns 0, consumes the entire input, and generates 9 characters "D`O'ExA^O". I believe that the call should return 6 in this case, since each of the six input characters were converted to "non-identical" characters in the output. The term "non-identical" is used in the return value description of: http://pubs.opengroup.org/onlinepubs/007908799/xsh/iconv.html For comparison, I tried this on MacOS, where the iconv() call returns -1, consumes no input, and generates no output. #include <iconv.h> #include <stdio.h> #include <string.h> int main(int argc, char **argv) { const char *input = "\303\220\303\222\303\211\303\227\303\205\303\224"; const char *in = input; size_t insize = strlen(in); char outbuff[64]; char *out = outbuff; size_t outsize = sizeof(outbuff); iconv_t cd = iconv_open("KOI8-R", "UTF-8"); size_t s = iconv(cd, &in, &insize, &out, &outsize); *out = '\0'; printf("s = %d\n", (int)s); printf("insize = %d\n", (int)insize); printf("outsize = %d\n", (int)outsize); printf("%s", outbuff); return (0); }help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F485CB54-88C7-4D5A-B3E8-AC5CF6DF226B>
