Back to index

glibc  2.9
bug-iconv2.c
Go to the documentation of this file.
00001 /* Test case by Akira Higuchi <a@kondara.org>.  */
00002 
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <iconv.h>
00006 
00007 int
00008 main (void)
00009 {
00010   const char *dummy_codesets[] =
00011   {
00012     "ISO_8859-1", "ISO_8859-2", "ISO_8859-3", "ISO_8859-4",
00013     "ISO_8859-5", "ISO_8859-6", "ISO_8859-7", "ISO_8859-8"
00014   };
00015   iconv_t dummy_cd[8], cd_a;
00016   int i;
00017   char buffer[1024], *to = buffer;
00018   char *from = (char *) "foobar";
00019   size_t to_left = 1024, from_left = 6;
00020 
00021   /* load dummy modules */
00022   for (i = 0; i < 8; i++)
00023     if ((dummy_cd[i] = iconv_open (dummy_codesets[i], "UTF8")) == (iconv_t) -1)
00024       exit (1);
00025 
00026   /* load a module... */
00027   if ((cd_a = iconv_open ("EUC-JP", "UTF8")) == (iconv_t) -1)
00028     exit (1);
00029   /* and close it once. we'll reload this later */
00030   iconv_close (cd_a);
00031 
00032   /* unload dummy modules */
00033   for (i = 0; i < 8; i++)
00034     iconv_close (dummy_cd[i]);
00035 
00036   /* load the module again */
00037   if ((cd_a = iconv_open ("EUC-JP", "UTF8")) == (iconv_t) -1)
00038     exit (1);
00039 
00040   puts ("This used to crash");
00041   printf ("%zd\n", iconv (cd_a, &from, &from_left, &to, &to_left));
00042   iconv_close (cd_a);
00043 
00044   puts ("works now");
00045 
00046   return 0;
00047 }