lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | // BZ 12601 |
| 2 | #include <stdio.h> |
| 3 | #include <errno.h> |
| 4 | #include <iconv.h> |
| 5 | |
| 6 | static int |
| 7 | do_test (void) |
| 8 | { |
| 9 | iconv_t cd; |
| 10 | char in[] = "\x83\xd9"; |
| 11 | char out[256]; |
| 12 | char *inbuf; |
| 13 | size_t inbytesleft; |
| 14 | char *outbuf; |
| 15 | size_t outbytesleft; |
| 16 | size_t ret; |
| 17 | |
| 18 | inbuf = in; |
| 19 | inbytesleft = sizeof(in) - 1; |
| 20 | outbuf = out; |
| 21 | outbytesleft = sizeof(out); |
| 22 | |
| 23 | cd = iconv_open("utf-8", "cp932"); |
| 24 | ret = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); |
| 25 | iconv_close(cd); |
| 26 | |
| 27 | printf("result: %zd %d %zd %d\n", ret, errno, inbytesleft, inbuf[0]); |
| 28 | |
| 29 | /* |
| 30 | * result: -1 84 0 0 (84=EILSEQ) |
| 31 | * |
| 32 | * Error is returnd but inbuf is consumed. |
| 33 | * |
| 34 | * \x83\xd9 is valid shift-jis sequence but no character is assigned |
| 35 | * to it. |
| 36 | */ |
| 37 | |
| 38 | return (ret != -1 || errno != EILSEQ |
| 39 | || inbytesleft != 2 || inbuf[0] != in[0]); |
| 40 | } |
| 41 | |
| 42 | #define TEST_FUNCTION do_test () |
| 43 | #include "../test-skeleton.c" |