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
main(int argc,char ** argv)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 (in);
24   outleft = outbufsize;
25 
26   cd = iconv_open ("SJIS", "eucJP");
27   if (cd == (iconv_t) -1)
28     {
29       puts ("iconv_open failed");
30       exit (1);
31     }
32 
33   iconv (cd, &in_p, &inleft, &out_p, &outleft); /* this returns E2BIG */
34   for (i = 0; i < outbufsize - outleft; ++i)
35     printf (" %02x", (unsigned char) out[i]);
36   puts ("");
37   iconv_close (cd);
38 
39   return outbufsize - outleft != 9 || memcmp (out, exp, 9) != 0;
40 }
41