Back to index

glibc  2.9
tst-iconv2.c
Go to the documentation of this file.
00001 /* Copyright (C) 2001 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <iconv.h>
00022 #include <mcheck.h>
00023 #include <stddef.h>
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 
00028 
00029 int
00030 main (void)
00031 {
00032   char buf[3];
00033   const wchar_t wc[1] = L"a";
00034   iconv_t cd;
00035   char *inptr;
00036   size_t inlen;
00037   char *outptr;
00038   size_t outlen;
00039   size_t n;
00040   int e;
00041   int result = 0;
00042 
00043   mtrace ();
00044 
00045   cd = iconv_open ("UCS4", "WCHAR_T");
00046   if (cd == (iconv_t) -1)
00047     {
00048       printf ("cannot convert from wchar_t to UCS4: %m\n");
00049       exit (1);
00050     }
00051 
00052   inptr = (char *) wc;
00053   inlen = sizeof (wchar_t);
00054   outptr = buf;
00055   outlen = 3;
00056 
00057   n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
00058   e = errno;
00059 
00060   if (n != (size_t) -1)
00061     {
00062       printf ("incorrect iconv() return value: %zd, expected -1\n", n);
00063       result = 1;
00064     }
00065 
00066   if (e != E2BIG)
00067     {
00068       printf ("incorrect error value: %s, expected %s\n",
00069              strerror (e), strerror (E2BIG));
00070       result = 1;
00071     }
00072 
00073   if (inptr != (char *) wc)
00074     {
00075       puts ("inptr changed");
00076       result = 1;
00077     }
00078 
00079   if (inlen != sizeof (wchar_t))
00080     {
00081       puts ("inlen changed");
00082       result = 1;
00083     }
00084 
00085   if (outptr != buf)
00086     {
00087       puts ("outptr changed");
00088       result = 1;
00089     }
00090 
00091   if (outlen != 3)
00092     {
00093       puts ("outlen changed");
00094       result = 1;
00095     }
00096 
00097   iconv_close (cd);
00098 
00099   return result;
00100 }