]>
Commit | Line | Data |
---|---|---|
61af4bbb | 1 | /* Test basic mbstowcs including wstring == NULL (Bug 25219). |
dff8da6b | 2 | Copyright (C) 2020-2024 Free Software Foundation, Inc. |
61af4bbb CD |
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 <stdlib.h> | |
20 | #include <string.h> | |
21 | #include <support/check.h> | |
22 | ||
23 | static int | |
24 | do_test (void) | |
25 | { | |
26 | char string[] = { '1', '2', '3' , '4', '5', '\0' }; | |
27 | size_t len = strlen (string); | |
28 | wchar_t wstring[] = { L'1', L'2', L'3', L'4', L'5', L'\0' }; | |
29 | #define NUM_WCHAR 6 | |
30 | wchar_t wout[NUM_WCHAR]; | |
31 | size_t result; | |
32 | ||
33 | /* The input ASCII string in the C/POSIX locale must convert | |
34 | to the matching WSTRING. */ | |
35 | result = mbstowcs (wout, string, NUM_WCHAR); | |
36 | TEST_VERIFY (result == (NUM_WCHAR - 1)); | |
37 | TEST_COMPARE_BLOB (wstring, sizeof (wchar_t) * (NUM_WCHAR - 1), | |
38 | wout, sizeof (wchar_t) * result); | |
39 | ||
40 | /* The input ASCII string in the C/POSIX locale must be the | |
41 | same length when using mbstowcs to compute the length of | |
42 | the string required in the conversion. Using mbstowcs | |
43 | in this way is an XSI extension to POSIX. */ | |
44 | result = mbstowcs (NULL, string, len); | |
45 | TEST_VERIFY (result == len); | |
46 | ||
47 | return 0; | |
48 | } | |
49 | ||
50 | #include <support/test-driver.c> |