Back to index

glibc  2.9
tst-iconv1.c
Go to the documentation of this file.
00001 /* Test case by yaoz@nih.gov.  */
00002 
00003 #include <iconv.h>
00004 #include <stddef.h>
00005 #include <stdio.h>
00006 #include <string.h>
00007 
00008 int
00009 main (void)
00010 {
00011   char utf8[5];
00012   wchar_t ucs4[5];
00013   iconv_t cd;
00014   char *inbuf;
00015   char *outbuf;
00016   size_t inbytes;
00017   size_t outbytes;
00018   size_t n;
00019 
00020   strcpy (utf8, "abcd");
00021 
00022   /* From UTF8 to UCS4. */
00023   cd = iconv_open ("UCS4", "UTF8");
00024   if (cd == (iconv_t) -1)
00025     {
00026       perror ("iconv_open");
00027       return 1;
00028     }
00029 
00030   inbuf = utf8;
00031   inbytes = 4;
00032   outbuf = (char *) ucs4;
00033   outbytes = 4 * sizeof (wchar_t);    /* "Argument list too long" error. */
00034   n = iconv (cd, &inbuf, &inbytes, &outbuf, &outbytes);
00035   if (n == (size_t) -1)
00036     {
00037       printf ("iconv: %m\n");
00038       iconv_close (cd);
00039       return 1;
00040     }
00041   iconv_close (cd);
00042 
00043   return 0;
00044 }