10 iconv_t h = iconv_open ("ISO-2022-JP-2", "UTF-8");
11 if (h == (iconv_t) -1)
13 printf ("cannot load iconv module: %m\n");
18 static const char inbuf[] = "\xe2\x82\xac";
19 char *in = (char *) inbuf;
20 size_t inlen = sizeof (inbuf) - 1;
24 size_t outlen = sizeof (outbuf);
27 size_t n = iconv (h, &in, &inlen, &out, &outlen);
30 printf ("iconv failed with %d: %m\n", errno);
35 printf ("iconv returned %zu, expected zero\n", n);
38 if (in != inbuf + sizeof (inbuf) - 1)
40 printf ("in advanced by %td, expected %zu\n",
41 in - inbuf, sizeof (inbuf) - 1);
44 static const char expected[] = "\x1b\x2e\x46\x1b\x4e\x24";
45 if (out - outbuf != sizeof (expected) - 1
46 || memcmp (outbuf, expected, sizeof (expected) - 1) != 0)
48 fputs ("generated sequence is: \"", stdout);
49 for (size_t i = 0; i < out - outbuf; ++i)
50 printf ("\\x%02hhx", outbuf[i]);
51 fputs ("\", expected \"", stdout);
52 for (size_t i = 0; i < sizeof (expected) - 1; ++i)
53 printf ("\\x%02hhx", expected[i]);
58 if (iconv_close (h) != 0)
60 puts ("failed closing iconv module");
67 #define TEST_FUNCTION do_test ()
68 #include "../test-skeleton.c"