1 | /* Test for invalid input to wcrtomb. |
2 | Copyright (C) 2001-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
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/>. */ |
18 | |
19 | #include <errno.h> |
20 | #include <locale.h> |
21 | #include <stdio.h> |
22 | #include <string.h> |
23 | #include <wchar.h> |
24 | |
25 | |
26 | static int |
27 | do_test (const char *loc) |
28 | { |
29 | char buf[100]; |
30 | size_t n; |
31 | mbstate_t state; |
32 | const char *nloc; |
33 | int res; |
34 | |
35 | nloc = setlocale (LC_ALL, loc); |
36 | if (nloc == NULL) |
37 | { |
38 | printf (format: "could not set locale \"%s\"\n" , loc); |
39 | return 1; |
40 | } |
41 | printf (format: "new locale: %s\n" , nloc); |
42 | |
43 | memset (&state, '\0', sizeof (state)); |
44 | errno = 0; |
45 | n = wcrtomb (buf, (wchar_t) -15l, &state); |
46 | |
47 | printf (format: "n = %zd, errno = %d (%s)\n" , n, errno, strerror (errno)); |
48 | |
49 | res = n != (size_t) -1 || errno != EILSEQ; |
50 | if (res) |
51 | puts (s: "*** FAIL" ); |
52 | putchar (c: '\n'); |
53 | |
54 | return res; |
55 | } |
56 | |
57 | |
58 | int |
59 | main (void) |
60 | { |
61 | int res; |
62 | |
63 | res = do_test (loc: "C" ); |
64 | res |= do_test (loc: "de_DE.ISO-8859-1" ); |
65 | res |= do_test (loc: "de_DE.UTF-8" ); |
66 | res |= do_test (loc: "en_US.ANSI_X3.4-1968" ); |
67 | res |= do_test (loc: "ja_JP.EUC-JP" ); |
68 | res |= do_test (loc: "hr_HR.ISO-8859-2" ); |
69 | //res |= do_test ("ru_RU.KOI8-R"); |
70 | |
71 | return res; |
72 | } |
73 | |