1 | /* Test program by Satoru Takabayashi. */ |
---|---|
2 | #include <errno.h> |
3 | #include <iconv.h> |
4 | #include <stdio.h> |
5 | #include <stdlib.h> |
6 | #include <string.h> |
7 | |
8 | int |
9 | main (int argc, char **argv) |
10 | { |
11 | const char in[] = "\x41\x42\x43\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa"; |
12 | /* valid eucJP string */ |
13 | const char exp[] = "\x41\x42\x43\x82\xa0\x82\xa2\x82\xa4"; |
14 | size_t outbufsize = 10; |
15 | /* 10 is too small to store full result (intentional) */ |
16 | size_t inleft, outleft; |
17 | char *in_p = (char *) in; |
18 | char out[outbufsize]; |
19 | char *out_p = out; |
20 | iconv_t cd; |
21 | int i; |
22 | |
23 | inleft = strlen (s: in); |
24 | outleft = outbufsize; |
25 | |
26 | cd = iconv_open (tocode: "SJIS", fromcode: "eucJP"); |
27 | if (cd == (iconv_t) -1) |
28 | { |
29 | puts (s: "iconv_open failed"); |
30 | exit (status: 1); |
31 | } |
32 | |
33 | iconv (cd: cd, inbuf: &in_p, inbytesleft: &inleft, outbuf: &out_p, outbytesleft: &outleft); /* this returns E2BIG */ |
34 | for (i = 0; i < outbufsize - outleft; ++i) |
35 | printf (format: " %02x", (unsigned char) out[i]); |
36 | puts (s: ""); |
37 | iconv_close (cd: cd); |
38 | |
39 | return outbufsize - outleft != 9 || memcmp (s1: out, s2: exp, n: 9) != 0; |
40 | } |
41 |