Back to index

glibc  2.9
tst-iconv4.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <iconv.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 
00007 
00008 static int
00009 do_test (void)
00010 {
00011   iconv_t cd = iconv_open ("ISO-8859-1", "UNICODE");
00012   if (cd == (iconv_t) -1)
00013     {
00014       printf ("iconv_open failed: %m\n");
00015       exit (EXIT_FAILURE);
00016     }
00017 
00018   char instr[] = "a";
00019   char *inptr = instr;
00020   size_t inlen = strlen (instr);
00021   char buf[200];
00022   char *outptr = buf;
00023   size_t outlen = sizeof (outptr);
00024 
00025   errno = 0;
00026   size_t n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
00027   if (n != (size_t) -1)
00028     {
00029       printf ("n (= %zu) != (size_t) -1\n", n);
00030       exit (EXIT_FAILURE);
00031     }
00032   if (errno != EINVAL)
00033     {
00034       printf ("errno = %m, not EINVAL\n");
00035       exit (EXIT_FAILURE);
00036     }
00037 
00038   iconv_close (cd);
00039 
00040   return 0;
00041 }
00042 
00043 #define TEST_FUNCTION do_test ()
00044 #include "../test-skeleton.c"