execute, spawn-pipe: Make multithread-safe on native Windows.
[gnulib.git] / lib / c32is-impl.h
blobfd5f06a409ac392ca7c9ae11ebfc38df66e84b8f
1 /* Test whether a 32-bit wide character belongs to a specific character class.
2 Copyright (C) 2020 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2020. */
19 #include <wchar.h>
20 #include <wctype.h>
22 #ifdef __CYGWIN__
23 # include <cygwin/version.h>
24 #endif
26 #if GNULIB_defined_mbstate_t
27 # include "localcharset.h"
28 # include "streq.h"
29 #endif
31 #include "unictype.h"
32 #include "verify.h"
34 int
35 FUNC (wint_t wc)
37 /* The char32_t encoding of a multibyte character is defined by the way
38 mbrtoc32() is defined. */
40 #if GNULIB_defined_mbstate_t /* AIX, IRIX */
41 /* mbrtoc32() is defined on top of mbtowc() for the non-UTF-8 locales
42 and directly for the UTF-8 locales. */
43 if (wc != WEOF)
45 const char *encoding = locale_charset ();
46 if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
47 return UCS_FUNC (wc);
48 else
49 return WCHAR_FUNC (wc);
51 else
52 return 0;
54 #elif HAVE_WORKING_MBRTOC32 /* glibc */
55 /* mbrtoc32() is essentially defined by the system libc. */
57 # if defined __GLIBC__
58 /* The char32_t encoding of a multibyte character is known to be the same as
59 the wchar_t encoding. */
60 return WCHAR_FUNC (wc);
61 # else
62 /* The char32_t encoding of a multibyte character is known to be UCS-4,
63 different from the the wchar_t encoding. */
64 if (wc != WEOF)
65 return UCS_FUNC (wc);
66 else
67 return 0;
68 # endif
70 #elif _GL_LARGE_CHAR32_T /* Cygwin, mingw, MSVC */
71 /* The wchar_t encoding is UTF-16.
72 The char32_t encoding is UCS-4. */
74 # if defined __CYGWIN__ && CYGWIN_VERSION_DLL_MAJOR >= 1007
75 /* As an extension to POSIX, the iswalnum() function of Cygwin >= 1.7
76 supports also wc arguments outside the Unicode BMP, that is, outside
77 the 'wchar_t' range. See
78 <https://lists.gnu.org/archive/html/bug-gnulib/2011-02/msg00019.html>
79 = <https://cygwin.com/ml/cygwin/2011-02/msg00044.html>. */
80 return WCHAR_FUNC (wc);
81 # else
82 if (wc == WEOF || wc == (wchar_t) wc)
83 /* wc is in the range for the isw* functions. */
84 return WCHAR_FUNC (wc);
85 else
86 return UCS_FUNC (wc);
87 # endif
89 #else /* macOS, FreeBSD, NetBSD, OpenBSD, HP-UX, Solaris, Minix, Android */
90 /* char32_t and wchar_t are equivalent. */
91 verify (sizeof (char32_t) == sizeof (wchar_t));
93 return WCHAR_FUNC (wc);
94 #endif