Back to index

glibc  2.9
bug-iconv6.c
Go to the documentation of this file.
00001 #include <string.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <errno.h>
00005 #include <iconv.h>
00006 #include <locale.h>
00007 
00008 static const char testbuf[] = {
00009        0xEF, 0xBE, 0x9F, 0xD0, 0xB4, 0xEF, 0xBE, 0x9F, 0x29, 0xEF, 0xBE, 0x8E,
00010        0xEF, 0xBE, 0x9F, 0xEF, 0xBD, 0xB6, 0xEF, 0xBD, 0xB0, 0xEF, 0xBE, 0x9D
00011 };
00012 
00013 static int
00014 do_test (void)
00015 {
00016   setlocale (LC_ALL, "de_DE.UTF-8");
00017   iconv_t ic = iconv_open ("ISO-2022-JP//TRANSLIT", "UTF-8");
00018   if (ic == (iconv_t) -1)
00019     {
00020       puts ("iconv_open failed");
00021       return 1;
00022     }
00023   size_t outremain = sizeof testbuf;
00024   char outbuf[outremain];
00025   char *inp = (char *) testbuf;
00026   char *outp = outbuf;
00027   size_t inremain = sizeof testbuf;
00028 
00029   int ret = iconv (ic, &inp, &inremain, &outp, &outremain);
00030 
00031   int result = 0;
00032   if (ret == (size_t) -1)
00033     {
00034       if (errno == E2BIG)
00035        puts ("buffer too small reported.  OK");
00036       else
00037        {
00038          printf ("iconv failed with %d (%m)\n", errno);
00039          result = 0;
00040        }
00041     }
00042   else
00043     {
00044       printf ("iconv returned %d\n", ret);
00045       result = 1;
00046     }
00047 
00048   return result;
00049 }
00050 
00051 #define TEST_FUNCTION do_test ()
00052 #include "../test-skeleton.c"