Back to index

glibc  2.9
bug-iconv5.c
Go to the documentation of this file.
00001 #include <iconv.h>
00002 #include <stdint.h>
00003 #include <stdio.h>
00004 
00005 
00006 static int
00007 do_test (void)
00008 {
00009   iconv_t cd = iconv_open ("utf-8", "unicode");
00010   if (cd == (iconv_t) -1)
00011     {
00012       puts ("cannot open iconv module");
00013       return 1;
00014     }
00015 
00016   static const uint16_t us[] = { 0xfeff, 0x0041, 0x0042, 0x0043 };
00017   char buf[100];
00018 
00019   char *inbuf;
00020   size_t inlen;
00021   char *outbuf;
00022   size_t outlen;
00023   size_t n;
00024 
00025   inbuf = (char *) us;
00026   inlen = sizeof (us);
00027   outbuf = buf;
00028   outlen = sizeof (buf);
00029   n = iconv (cd, &inbuf, &inlen, &outbuf, &outlen);
00030   if (n == (size_t) -1 || inlen != 0 || outlen != sizeof (buf) - 3)
00031     {
00032       puts ("first conversion failed");
00033       return 1;
00034     }
00035 
00036   iconv (cd, NULL, NULL, NULL, NULL);
00037 
00038   inbuf = (char *) us;
00039   inlen = sizeof (us);
00040   outbuf = buf;
00041   outlen = sizeof (buf);
00042   n = iconv (cd, &inbuf, &inlen, &outbuf, &outlen);
00043   if (n == (size_t) -1 || inlen != 0 || outlen != sizeof (buf) - 3)
00044     {
00045       puts ("second conversion failed");
00046       return 1;
00047     }
00048 
00049   return 0;
00050 }
00051 
00052 #define TEST_FUNCTION do_test ()
00053 #include "../test-skeleton.c"