Back to index

glibc  2.9
tst-mbswcs4.c
Go to the documentation of this file.
00001 /* Test restarting behaviour of mbsrtowcs.
00002    Copyright (C) 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
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 <stdio.h>
00021 #include <string.h>
00022 #include <wchar.h>
00023 #include <locale.h>
00024 
00025 #define show(expr, nexp, wcexp, end) \
00026   n = expr;                                                    \
00027   printf (#expr " -> %Zd", n);                                        \
00028   printf (", wc = %lu, src = buf+%d", (unsigned long int) wc,         \
00029          src - (const char *) buf);                                   \
00030   if (n != (size_t) nexp || wc != wcexp || src != (const char *) (end))      \
00031     {                                                          \
00032       printf (", expected %Zd and %lu and buf+%d", nexp,              \
00033              (unsigned long int) wcexp, (end) - buf);                 \
00034       result = 1;                                              \
00035     }                                                          \
00036   putc ('\n', stdout)
00037 
00038 int
00039 main (void)
00040 {
00041   unsigned char buf[6] = { 0x25,  0xe2, 0x82, 0xac,  0xce, 0xbb };
00042   mbstate_t state;
00043   const char *src;
00044   wchar_t wc = 42;
00045   size_t n;
00046   int result = 0;
00047   const char *used_locale;
00048 
00049   setlocale (LC_CTYPE,"de_DE.UTF-8");
00050   /* Double check.  */
00051   used_locale = setlocale (LC_CTYPE, NULL);
00052   printf ("used locale: \"%s\"\n", used_locale);
00053   result = strcmp (used_locale, "de_DE.UTF-8");
00054 
00055   memset (&state, '\0', sizeof (state));
00056 
00057   src = (const char *) buf;
00058   show (mbsrtowcs (&wc, &src, 1, &state), 1, 37, buf + 1);
00059   show (mbsrtowcs (&wc, &src, 1, &state), 1, 8364, buf + 4);
00060   show (mbsrtowcs (&wc, &src, 1, &state), 1, 955, buf + 6);
00061 
00062   return result;
00063 }