Implement C23 <stdbit.h>
[glibc.git] / localedata / tst-mbswcs6.c
blobb77ea0cce9b18680f4cdcda9a9c7f93ff9b765cb
1 /* Test for invalid input to wcrtomb.
2 Copyright (C) 2001-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <locale.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <wchar.h>
26 static int
27 do_test (const char *loc)
29 char buf[100];
30 size_t n;
31 mbstate_t state;
32 const char *nloc;
33 int res;
35 nloc = setlocale (LC_ALL, loc);
36 if (nloc == NULL)
38 printf ("could not set locale \"%s\"\n", loc);
39 return 1;
41 printf ("new locale: %s\n", nloc);
43 memset (&state, '\0', sizeof (state));
44 errno = 0;
45 n = wcrtomb (buf, (wchar_t) -15l, &state);
47 printf ("n = %zd, errno = %d (%s)\n", n, errno, strerror (errno));
49 res = n != (size_t) -1 || errno != EILSEQ;
50 if (res)
51 puts ("*** FAIL");
52 putchar ('\n');
54 return res;
58 int
59 main (void)
61 int res;
63 res = do_test ("C");
64 res |= do_test ("de_DE.ISO-8859-1");
65 res |= do_test ("de_DE.UTF-8");
66 res |= do_test ("en_US.ANSI_X3.4-1968");
67 res |= do_test ("ja_JP.EUC-JP");
68 res |= do_test ("hr_HR.ISO-8859-2");
69 //res |= do_test ("ru_RU.KOI8-R");
71 return res;