Back to index

glibc  2.9
tst-mbswcs2.c
Go to the documentation of this file.
00001 /* Test restarting behaviour of mbsnrtowcs.
00002    Copyright (C) 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Bruno Haible <haible@ilog.fr>.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <wchar.h>
00024 #include <locale.h>
00025 
00026 #define show(expr, nexp, wcexp, end) \
00027   n = expr;                                                    \
00028   printf (#expr " -> %Zd", n);                                        \
00029   printf (", wc = %lu, src = buf+%d", (unsigned long int) wc,         \
00030          src - (const char *) buf);                                   \
00031   if (n != (size_t) nexp || wc != wcexp || src != (const char *) (end))      \
00032     {                                                          \
00033       printf (", expected %Zd and %lu and buf+%d", nexp,              \
00034              (unsigned long int) wcexp, (end) - buf);                 \
00035       result = 1;                                              \
00036     }                                                          \
00037   putc ('\n', stdout)
00038 
00039 int
00040 main (void)
00041 {
00042   unsigned char buf[6] = { 0x25,  0xe2, 0x82, 0xac,  0xce, 0xbb };
00043   mbstate_t state;
00044   const char *src;
00045   wchar_t wc = 42;
00046   size_t n;
00047   int result = 0;
00048   const char *used_locale;
00049 
00050   setlocale (LC_CTYPE,"de_DE.UTF-8");
00051   /* Double check.  */
00052   used_locale = setlocale (LC_CTYPE, NULL);
00053   printf ("used locale: \"%s\"\n", used_locale);
00054   result = strcmp (used_locale, "de_DE.UTF-8");
00055 
00056   memset (&state, '\0', sizeof (state));
00057 
00058   src = (const char *) buf;
00059   show (mbsnrtowcs (&wc, &src, 1, 1, &state), 1, 37, buf + 1);
00060   show (mbsnrtowcs (&wc, &src, 3, 1, &state), 1, 8364, buf + 4);
00061   show (mbsnrtowcs (&wc, &src, 1, 1, &state), 0, 8364, buf + 5);
00062   show (mbsnrtowcs (&wc, &src, 1, 1, &state), 1, 955, buf + 6);
00063 
00064   return result;
00065 }