Back to index

glibc  2.9
bug-iconv-trans.c
Go to the documentation of this file.
00001 #include <iconv.h>
00002 #include <locale.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 
00006 int
00007 main (void)
00008 {
00009   iconv_t cd;
00010   const char str[] = "";
00011   const char expected[] = "AEaeOEoeUEuess";
00012   char *inptr = (char *) str;
00013   size_t inlen = strlen (str) + 1;
00014   char outbuf[500];
00015   char *outptr = outbuf;
00016   size_t outlen = sizeof (outbuf);
00017   int result = 0;
00018   size_t n;
00019 
00020   if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
00021     {
00022       puts ("setlocale failed");
00023       return 1;
00024     }
00025 
00026   cd = iconv_open ("ANSI_X3.4-1968//TRANSLIT", "ISO-8859-1");
00027   if (cd == (iconv_t) -1)
00028     {
00029       puts ("iconv_open failed");
00030       return 1;
00031     }
00032 
00033   n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
00034   if (n != 7)
00035     {
00036       if (n == (size_t) -1)
00037        printf ("iconv() returned error: %m\n");
00038       else
00039        printf ("iconv() returned %Zd, expected 7\n", n);
00040       result = 1;
00041     }
00042   if (inlen != 0)
00043     {
00044       puts ("not all input consumed");
00045       result = 1;
00046     }
00047   else if (inptr - str != strlen (str) + 1)
00048     {
00049       printf ("inptr wrong, advanced by %td\n", inptr - str);
00050       result = 1;
00051     }
00052   if (memcmp (outbuf, expected, sizeof (expected)) != 0)
00053     {
00054       printf ("result wrong: \"%.*s\", expected: \"%s\"\n",
00055              (int) (sizeof (outbuf) - outlen), outbuf, expected);
00056       result = 1;
00057     }
00058   else if (outlen != sizeof (outbuf) - sizeof (expected))
00059     {
00060       printf ("outlen wrong: %Zd, expected %Zd\n", outlen,
00061              sizeof (outbuf) - 15);
00062       result = 1;
00063     }
00064   else
00065     printf ("output is \"%s\" which is OK\n", outbuf);
00066 
00067   return result;
00068 }