Debian Codegraph @

gnulib-tests/test-localcharset-w32utf8.c

raw
1 /* Test of localcharset() function
2 on native Windows in the UTF-8 environment.
3 Copyright (C) 2024-2025 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18 /* Written by Bruno Haible <[email protected]>, 2024. */
19
20 #include <config.h>
21
22 #include "localcharset.h"
23
24 #include <locale.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28
29 #define WIN32_LEAN_AND_MEAN
30 #include <windows.h>
31
32 int
33 main (void)
34 {
35 #ifdef _UCRT
36 unsigned int active_codepage = GetACP ();
37 if (!(active_codepage == 65001))
38 {
39 fprintf (stderr,
40 "The active codepage is %u, not 65001 as expected.\n"
41 "(This is normal on Windows older than Windows 10.)\n",
42 active_codepage);
43 exit (1);
44 }
45
46 setlocale (LC_ALL, "");
47 const char *lc = locale_charset ();
48 if (!(strcmp (lc, "UTF-8") == 0))
49 {
50 fprintf (stderr,
51 "locale_charset () is \"%s\", not \"UTF-8\" as expected.\n",
52 lc);
53 exit (1);
54 }
55
56 return 0;
57 #else
58 fputs ("Skipping test: not using the UCRT runtime\n", stderr);
59 return 77;
60 #endif
61 }