Back to index

glibc  2.9
tst-iconv3.c
Go to the documentation of this file.
00001 /* Contributed by Owen Taylor <otaylor@redhat.com>.  */
00002 
00003 #include <iconv.h>
00004 #include <errno.h>
00005 #include <stddef.h>
00006 #include <stdio.h>
00007 
00008 #define BUFSIZE 10000
00009 
00010 int
00011 main (int argc, char *argv[])
00012 {
00013   char inbuf[BUFSIZE];
00014   wchar_t outbuf[BUFSIZE];
00015 
00016   iconv_t cd;
00017   int i;
00018   char *inptr;
00019   char *outptr;
00020   size_t inbytes_left, outbytes_left;
00021   int count;
00022   int result = 0;
00023 
00024   for (i=0; i < BUFSIZE; i++)
00025     inbuf[i] = 'a';
00026 
00027   cd = iconv_open ("UCS-4LE", "UTF-8");
00028 
00029   inbytes_left = BUFSIZE;
00030   outbytes_left = BUFSIZE * 4;
00031   inptr = inbuf;
00032   outptr = (char *) outbuf;
00033 
00034   count = iconv (cd, &inptr, &inbytes_left, &outptr, &outbytes_left);
00035 
00036   if (count < 0)
00037     {
00038       if (errno == E2BIG)
00039        printf ("Received E2BIG\n");
00040       else
00041        printf ("Received something else\n");
00042 
00043       printf ("inptr change: %td\n", inptr - inbuf);
00044       printf ("inlen change: %zd\n", BUFSIZE - inbytes_left);
00045       printf ("outptr change: %td\n", outptr - (char *) outbuf);
00046       printf ("outlen change: %zd\n", BUFSIZE * 4 - outbytes_left);
00047       result = 1;
00048     }
00049   else
00050     printf ("Succeeded\n");
00051 
00052   return result;
00053 }