1 /* <uchar.h> substitute - 16-bit and 32-bit wide character types.
2 Copyright (C) 2019-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2019. */
18
19 /*
20 * ISO C 23 <uchar.h> for platforms that lack it.
21 */
22
23 #ifndef _@GUARD_PREFIX@_UCHAR_H
24
25 #if __GNUC__ >= 3
26 @PRAGMA_SYSTEM_HEADER@
27 #endif
28 @PRAGMA_COLUMNS@
29
30 /* The include_next requires a split double-inclusion guard. */
31 #if @HAVE_UCHAR_H@
32 # if defined __HAIKU__
33 /* Work around <https://dev.haiku-os.org/ticket/17040>. */
34 # include <stdint.h>
35 # endif
36 /* On AIX 7.2 with xlclang++, /usr/include/uchar.h produces compilation errors
37 because it contains typedef definitions of char16_t and char32_t, however
38 char16_t and char32_t are keywords in this situation. To work around it,
39 define char16_t and char32_t as macros. */
40 # if defined __cplusplus && defined _AIX && defined __ibmxl__ && defined __clang__
41 # define char16_t gl_char16_t
42 # define char32_t gl_char32_t
43 # endif
44 # @INCLUDE_NEXT@ @NEXT_UCHAR_H@
45 #endif
46
47 #ifndef _@GUARD_PREFIX@_UCHAR_H
48 #define _@GUARD_PREFIX@_UCHAR_H
49
50 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_BEGIN_C_LINKAGE,
51 _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
52 #if !_GL_CONFIG_H_INCLUDED
53 #error "Please include config.h first."
54 #endif
55
56 /* Get uint_least16_t, uint_least32_t. */
57 #include <stdint.h>
58
59 /* Get mbstate_t, size_t. */
60 #include <wchar.h>
61
62 /* For the inline functions. */
63 #include <string.h>
64 #include <wctype.h>
65
66 /* The __attribute__ feature is available in gcc versions 2.5 and later.
67 The attribute __pure__ was added in gcc 2.96. */
68 #ifndef _GL_ATTRIBUTE_PURE
69 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
70 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
71 # else
72 # define _GL_ATTRIBUTE_PURE /* empty */
73 # endif
74 #endif
75
76 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
77
78 /* The definition of _GL_ARG_NONNULL is copied here. */
79
80 /* The definition of _GL_WARN_ON_USE is copied here. */
81
82
83 _GL_INLINE_HEADER_BEGIN
84
85
86 #if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_CHAR8_TYPE@))
87
88 /* An 8-bit variant of wchar_t.
89 Note: This type is only mandated by ISO C 23 or newer, and it does
90 denote UTF-8 units. */
91 typedef unsigned char char8_t;
92
93 #elif @GNULIBHEADERS_OVERRIDE_CHAR8_T@
94
95 typedef unsigned char gl_char8_t;
96 # define char8_t gl_char8_t
97
98 #endif
99
100 #if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_UCHAR_TYPES@))
101
102 /* A 16-bit variant of wchar_t.
103 Note: This type is only mandated by ISO C 11 or newer. In ISO C 23
104 and newer, it denotes UTF-16 units; in older versions of ISO C it did
105 so only on platforms on which __STDC_UTF_16__ was defined. */
106 typedef uint_least16_t char16_t;
107
108 #elif @GNULIBHEADERS_OVERRIDE_CHAR16_T@
109
110 typedef uint_least16_t gl_char16_t;
111 # define char16_t gl_char16_t
112
113 #endif
114
115 #if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_UCHAR_TYPES@))
116
117 /* A 32-bit variant of wchar_t.
118 Note: This type is only mandated by ISO C 11 or newer. In ISO C 23
119 and newer, it denotes UTF-32 code points; in older versions of ISO C
120 it did so only on platforms on which __STDC_UTF_32__ was defined.
121 In gnulib, we guarantee that it denotes UTF-32 code points if and
122 only if the module 'uchar-c23' is in use. */
123 typedef uint_least32_t char32_t;
124
125 #elif @GNULIBHEADERS_OVERRIDE_CHAR32_T@
126
127 typedef uint_least32_t gl_char32_t;
128 # define char32_t gl_char32_t
129
130 #endif
131
132 /* Define if a 'char32_t' can hold more characters than a 'wchar_t'. */
133 #if @SMALL_WCHAR_T@ /* 32-bit AIX, Cygwin, native Windows */
134 # define _GL_SMALL_WCHAR_T 1
135 #endif
136
137 /* Define if 'wchar_t', like 'char32_t',
138 - is a 32-bit type, and
139 - represents Unicode code points.
140 For this test, we can use __STDC_ISO_10646__ (defined by glibc, musl libc,
141 Cygwin) but need to consider _GL_SMALL_WCHAR_T, so as to exclude Cygwin.
142 We cannot use __STDC_UTF_16__ or __STDC_UTF_32__
143 - because these macros provide info about char16_t and char32_t (not
144 wchar_t!), and
145 - because GCC >= 4.9 defines these macros on all platforms, even on
146 FreeBSD and Solaris.
147 We should better not use __STD_UTF_16__, __STD_UTF_32__ either, because
148 these macros are misspellings, only defined by Android's <uchar.h>. */
149 #if defined __STDC_ISO_10646__ && !_GL_SMALL_WCHAR_T
150 /* glibc, musl libc */
151 # define _GL_WCHAR_T_IS_UCS4 1
152 #endif
153 #if _GL_WCHAR_T_IS_UCS4
154 static_assert (sizeof (char32_t) == sizeof (wchar_t));
155 #endif
156
157
158 /* Convert a single-byte character to a 32-bit wide character. */
159 #if @GNULIB_BTOC32@
160 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_BTOC32
161 _GL_BEGIN_C_LINKAGE
162 _GL_INLINE _GL_ATTRIBUTE_PURE wint_t
163 btoc32 (int c)
164 {
165 return btowc (c);
166 }
167 _GL_END_C_LINKAGE
168 # else
169 _GL_FUNCDECL_SYS (btoc32, wint_t, (int c) _GL_ATTRIBUTE_PURE);
170 # endif
171 _GL_CXXALIAS_SYS (btoc32, wint_t, (int c));
172 _GL_CXXALIASWARN (btoc32);
173 #endif
174
175
176 /* Test a specific property of a 32-bit wide character. */
177 #if @GNULIB_C32ISALNUM@
178 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISALNUM
179 _GL_BEGIN_C_LINKAGE
180 _GL_INLINE int
181 c32isalnum (wint_t wc)
182 {
183 return iswalnum (wc);
184 }
185 _GL_END_C_LINKAGE
186 # else
187 _GL_FUNCDECL_SYS (c32isalnum, int, (wint_t wc));
188 # endif
189 _GL_CXXALIAS_SYS (c32isalnum, int, (wint_t wc));
190 _GL_CXXALIASWARN (c32isalnum);
191 #endif
192 #if @GNULIB_C32ISALPHA@
193 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISALPHA
194 _GL_BEGIN_C_LINKAGE
195 _GL_INLINE int
196 c32isalpha (wint_t wc)
197 {
198 return iswalpha (wc);
199 }
200 _GL_END_C_LINKAGE
201 # else
202 _GL_FUNCDECL_SYS (c32isalpha, int, (wint_t wc));
203 # endif
204 _GL_CXXALIAS_SYS (c32isalpha, int, (wint_t wc));
205 _GL_CXXALIASWARN (c32isalpha);
206 #endif
207 #if @GNULIB_C32ISBLANK@
208 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISBLANK
209 _GL_BEGIN_C_LINKAGE
210 _GL_INLINE int
211 c32isblank (wint_t wc)
212 {
213 return iswblank (wc);
214 }
215 _GL_END_C_LINKAGE
216 # else
217 _GL_FUNCDECL_SYS (c32isblank, int, (wint_t wc));
218 # endif
219 _GL_CXXALIAS_SYS (c32isblank, int, (wint_t wc));
220 _GL_CXXALIASWARN (c32isblank);
221 #endif
222 #if @GNULIB_C32ISCNTRL@
223 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISCNTRL
224 _GL_BEGIN_C_LINKAGE
225 _GL_INLINE int
226 c32iscntrl (wint_t wc)
227 {
228 return iswcntrl (wc);
229 }
230 _GL_END_C_LINKAGE
231 # else
232 _GL_FUNCDECL_SYS (c32iscntrl, int, (wint_t wc));
233 # endif
234 _GL_CXXALIAS_SYS (c32iscntrl, int, (wint_t wc));
235 _GL_CXXALIASWARN (c32iscntrl);
236 #endif
237 #if @GNULIB_C32ISDIGIT@
238 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISDIGIT
239 _GL_BEGIN_C_LINKAGE
240 _GL_INLINE int
241 c32isdigit (wint_t wc)
242 {
243 return iswdigit (wc);
244 }
245 _GL_END_C_LINKAGE
246 # else
247 _GL_FUNCDECL_SYS (c32isdigit, int, (wint_t wc));
248 # endif
249 _GL_CXXALIAS_SYS (c32isdigit, int, (wint_t wc));
250 _GL_CXXALIASWARN (c32isdigit);
251 #endif
252 #if @GNULIB_C32ISGRAPH@
253 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISGRAPH
254 _GL_BEGIN_C_LINKAGE
255 _GL_INLINE int
256 c32isgraph (wint_t wc)
257 {
258 return iswgraph (wc);
259 }
260 _GL_END_C_LINKAGE
261 # else
262 _GL_FUNCDECL_SYS (c32isgraph, int, (wint_t wc));
263 # endif
264 _GL_CXXALIAS_SYS (c32isgraph, int, (wint_t wc));
265 _GL_CXXALIASWARN (c32isgraph);
266 #endif
267 #if @GNULIB_C32ISLOWER@
268 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISLOWER
269 _GL_BEGIN_C_LINKAGE
270 _GL_INLINE int
271 c32islower (wint_t wc)
272 {
273 return iswlower (wc);
274 }
275 _GL_END_C_LINKAGE
276 # else
277 _GL_FUNCDECL_SYS (c32islower, int, (wint_t wc));
278 # endif
279 _GL_CXXALIAS_SYS (c32islower, int, (wint_t wc));
280 _GL_CXXALIASWARN (c32islower);
281 #endif
282 #if @GNULIB_C32ISPRINT@
283 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISPRINT
284 _GL_BEGIN_C_LINKAGE
285 _GL_INLINE int
286 c32isprint (wint_t wc)
287 {
288 return iswprint (wc);
289 }
290 _GL_END_C_LINKAGE
291 # else
292 _GL_FUNCDECL_SYS (c32isprint, int, (wint_t wc));
293 # endif
294 _GL_CXXALIAS_SYS (c32isprint, int, (wint_t wc));
295 _GL_CXXALIASWARN (c32isprint);
296 #endif
297 #if @GNULIB_C32ISPUNCT@
298 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISPUNCT
299 _GL_BEGIN_C_LINKAGE
300 _GL_INLINE int
301 c32ispunct (wint_t wc)
302 {
303 return iswpunct (wc);
304 }
305 _GL_END_C_LINKAGE
306 # else
307 _GL_FUNCDECL_SYS (c32ispunct, int, (wint_t wc));
308 # endif
309 _GL_CXXALIAS_SYS (c32ispunct, int, (wint_t wc));
310 _GL_CXXALIASWARN (c32ispunct);
311 #endif
312 #if @GNULIB_C32ISSPACE@
313 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISSPACE
314 _GL_BEGIN_C_LINKAGE
315 _GL_INLINE int
316 c32isspace (wint_t wc)
317 {
318 return iswspace (wc);
319 }
320 _GL_END_C_LINKAGE
321 # else
322 _GL_FUNCDECL_SYS (c32isspace, int, (wint_t wc));
323 # endif
324 _GL_CXXALIAS_SYS (c32isspace, int, (wint_t wc));
325 _GL_CXXALIASWARN (c32isspace);
326 #endif
327 #if @GNULIB_C32ISUPPER@
328 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISUPPER
329 _GL_BEGIN_C_LINKAGE
330 _GL_INLINE int
331 c32isupper (wint_t wc)
332 {
333 return iswupper (wc);
334 }
335 _GL_END_C_LINKAGE
336 # else
337 _GL_FUNCDECL_SYS (c32isupper, int, (wint_t wc));
338 # endif
339 _GL_CXXALIAS_SYS (c32isupper, int, (wint_t wc));
340 _GL_CXXALIASWARN (c32isupper);
341 #endif
342 #if @GNULIB_C32ISXDIGIT@
343 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISXDIGIT
344 _GL_BEGIN_C_LINKAGE
345 _GL_INLINE int
346 c32isxdigit (wint_t wc)
347 {
348 return iswxdigit (wc);
349 }
350 _GL_END_C_LINKAGE
351 # else
352 _GL_FUNCDECL_SYS (c32isxdigit, int, (wint_t wc));
353 # endif
354 _GL_CXXALIAS_SYS (c32isxdigit, int, (wint_t wc));
355 _GL_CXXALIASWARN (c32isxdigit);
356 #endif
357
358
359 /* Case mapping of a 32-bit wide character. */
360 #if @GNULIB_C32TOLOWER@
361 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32TOLOWER
362 _GL_BEGIN_C_LINKAGE
363 _GL_INLINE wint_t
364 c32tolower (wint_t wc)
365 {
366 return towlower (wc);
367 }
368 _GL_END_C_LINKAGE
369 # else
370 _GL_FUNCDECL_SYS (c32tolower, wint_t, (wint_t wc));
371 # endif
372 _GL_CXXALIAS_SYS (c32tolower, wint_t, (wint_t wc));
373 _GL_CXXALIASWARN (c32tolower);
374 #endif
375 #if @GNULIB_C32TOUPPER@
376 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32TOUPPER
377 _GL_BEGIN_C_LINKAGE
378 _GL_INLINE wint_t
379 c32toupper (wint_t wc)
380 {
381 return towupper (wc);
382 }
383 _GL_END_C_LINKAGE
384 # else
385 _GL_FUNCDECL_SYS (c32toupper, wint_t, (wint_t wc));
386 # endif
387 _GL_CXXALIAS_SYS (c32toupper, wint_t, (wint_t wc));
388 _GL_CXXALIASWARN (c32toupper);
389 #endif
390
391
392 /* Number of screen columns needed for a 32-bit wide character. */
393 #if @GNULIB_C32WIDTH@
394 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32WIDTH
395 _GL_BEGIN_C_LINKAGE
396 _GL_INLINE int
397 c32width (char32_t wc)
398 {
399 return wcwidth (wc);
400 }
401 _GL_END_C_LINKAGE
402 # else
403 _GL_FUNCDECL_SYS (c32width, int, (char32_t wc));
404 # endif
405 _GL_CXXALIAS_SYS (c32width, int, (char32_t wc));
406 _GL_CXXALIASWARN (c32width);
407 #endif
408
409
410 /* Converts a 32-bit wide character to a multibyte character. */
411 #if @GNULIB_C32RTOMB@
412 # if @REPLACE_C32RTOMB@
413 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
414 # undef c32rtomb
415 # define c32rtomb rpl_c32rtomb
416 # endif
417 _GL_FUNCDECL_RPL (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
418 _GL_CXXALIAS_RPL (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
419 # else
420 # if !@HAVE_C32RTOMB@
421 _GL_FUNCDECL_SYS (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
422 # endif
423 _GL_CXXALIAS_SYS (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
424 # endif
425 # if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
426 _GL_CXXALIASWARN (c32rtomb);
427 # endif
428 #elif defined GNULIB_POSIXCHECK
429 # undef c32rtomb
430 # if HAVE_RAW_DECL_C32RTOMB
431 _GL_WARN_ON_USE (c32rtomb, "c32rtomb is not portable - "
432 "use gnulib module c32rtomb for portability");
433 # endif
434 #endif
435
436
437 /* Convert a 32-bit wide string to a string. */
438 #if @GNULIB_C32SNRTOMBS@
439 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32SNRTOMBS
440 _GL_BEGIN_C_LINKAGE
441 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
442 c32snrtombs (char *dest, const char32_t **srcp, size_t srclen, size_t len,
443 mbstate_t *ps)
444 {
445 return wcsnrtombs (dest, (const wchar_t **) srcp, srclen, len, ps);
446 }
447 _GL_END_C_LINKAGE
448 # else
449 _GL_FUNCDECL_SYS (c32snrtombs, size_t,
450 (char *dest, const char32_t **srcp, size_t srclen, size_t len,
451 mbstate_t *ps)
452 _GL_ARG_NONNULL ((2)));
453 # endif
454 _GL_CXXALIAS_SYS (c32snrtombs, size_t,
455 (char *dest, const char32_t **srcp, size_t srclen, size_t len,
456 mbstate_t *ps));
457 _GL_CXXALIASWARN (c32snrtombs);
458 #endif
459
460
461 /* Convert a 32-bit wide string to a string. */
462 #if @GNULIB_C32SRTOMBS@
463 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32SRTOMBS
464 _GL_BEGIN_C_LINKAGE
465 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
466 c32srtombs (char *dest, const char32_t **srcp, size_t len, mbstate_t *ps)
467 {
468 return wcsrtombs (dest, (const wchar_t **) srcp, len, ps);
469 }
470 _GL_END_C_LINKAGE
471 # else
472 _GL_FUNCDECL_SYS (c32srtombs, size_t,
473 (char *dest, const char32_t **srcp, size_t len, mbstate_t *ps)
474 _GL_ARG_NONNULL ((2)));
475 # endif
476 _GL_CXXALIAS_SYS (c32srtombs, size_t,
477 (char *dest, const char32_t **srcp, size_t len,
478 mbstate_t *ps));
479 _GL_CXXALIASWARN (c32srtombs);
480 #endif
481
482
483 /* Convert a 32-bit wide string to a string. */
484 #if @GNULIB_C32STOMBS@
485 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32STOMBS
486 _GL_BEGIN_C_LINKAGE
487 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
488 c32stombs (char *dest, const char32_t *src, size_t len)
489 {
490 mbstate_t state;
491
492 mbszero (&state);
493 return c32srtombs (dest, &src, len, &state);
494 }
495 _GL_END_C_LINKAGE
496 # else
497 _GL_FUNCDECL_SYS (c32stombs, size_t,
498 (char *dest, const char32_t *src, size_t len)
499 _GL_ARG_NONNULL ((2)));
500 # endif
501 _GL_CXXALIAS_SYS (c32stombs, size_t,
502 (char *dest, const char32_t *src, size_t len));
503 _GL_CXXALIASWARN (c32stombs);
504 #endif
505
506
507 /* Number of screen columns needed for a size-bounded 32-bit wide string. */
508 #if @GNULIB_C32SWIDTH@
509 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32SWIDTH
510 _GL_BEGIN_C_LINKAGE
511 _GL_INLINE _GL_ARG_NONNULL ((1)) int
512 c32swidth (const char32_t *s, size_t n)
513 {
514 return wcswidth ((const wchar_t *) s, n);
515 }
516 _GL_END_C_LINKAGE
517 # else
518 _GL_FUNCDECL_SYS (c32swidth, int, (const char32_t *s, size_t n)
519 _GL_ARG_NONNULL ((1)));
520 # endif
521 _GL_CXXALIAS_SYS (c32swidth, int, (const char32_t *s, size_t n));
522 _GL_CXXALIASWARN (c32swidth);
523 #endif
524
525
526 /* Converts a 32-bit wide character to unibyte character.
527 Returns the single-byte representation of WC if it exists,
528 or EOF otherwise. */
529 #if @GNULIB_C32TOB@
530 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32TOB
531 _GL_BEGIN_C_LINKAGE
532 _GL_INLINE int
533 c32tob (wint_t wc)
534 {
535 return wctob (wc);
536 }
537 _GL_END_C_LINKAGE
538 # else
539 _GL_FUNCDECL_SYS (c32tob, int, (wint_t wc));
540 # endif
541 _GL_CXXALIAS_SYS (c32tob, int, (wint_t wc));
542 _GL_CXXALIASWARN (c32tob);
543 #endif
544
545
546 /* Converts a multibyte character to a 32-bit wide character. */
547 #if @GNULIB_MBRTOC32@
548 # if @REPLACE_MBRTOC32@
549 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
550 # undef mbrtoc32
551 # define mbrtoc32 rpl_mbrtoc32
552 # endif
553 _GL_FUNCDECL_RPL (mbrtoc32, size_t,
554 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
555 _GL_CXXALIAS_RPL (mbrtoc32, size_t,
556 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
557 # else
558 # if !@HAVE_MBRTOC32@
559 _GL_FUNCDECL_SYS (mbrtoc32, size_t,
560 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
561 # endif
562 _GL_CXXALIAS_SYS (mbrtoc32, size_t,
563 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
564 # endif
565 # if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
566 _GL_CXXALIASWARN (mbrtoc32);
567 # endif
568 #elif defined GNULIB_POSIXCHECK
569 # undef mbrtoc32
570 # if HAVE_RAW_DECL_MBRTOC32
571 _GL_WARN_ON_USE (mbrtoc32, "mbrtoc32 is not portable - "
572 "use gnulib module mbrtoc32 for portability");
573 # endif
574 #endif
575
576
577 /* Converts a multibyte character and returns the next 16-bit wide
578 character. */
579 #if @GNULIB_MBRTOC16@
580 # if @REPLACE_MBRTOC16@
581 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
582 # undef mbrtoc16
583 # define mbrtoc16 rpl_mbrtoc16
584 # endif
585 _GL_FUNCDECL_RPL (mbrtoc16, size_t,
586 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
587 _GL_CXXALIAS_RPL (mbrtoc16, size_t,
588 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
589 # else
590 # if !@HAVE_MBRTOC32@
591 _GL_FUNCDECL_SYS (mbrtoc16, size_t,
592 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
593 # endif
594 _GL_CXXALIAS_SYS (mbrtoc16, size_t,
595 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
596 # endif
597 # if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
598 _GL_CXXALIASWARN (mbrtoc16);
599 # endif
600 #elif defined GNULIB_POSIXCHECK
601 # undef mbrtoc16
602 # if HAVE_RAW_DECL_MBRTOC16
603 _GL_WARN_ON_USE (mbrtoc16, "mbrtoc16 is not portable - "
604 "use gnulib module mbrtoc16 for portability");
605 # endif
606 #endif
607
608
609 /* Convert a string to a 32-bit wide string. */
610 #if @GNULIB_MBSNRTOC32S@
611 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_MBSNRTOC32S
612 _GL_BEGIN_C_LINKAGE
613 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
614 mbsnrtoc32s (char32_t *dest, const char **srcp, size_t srclen, size_t len,
615 mbstate_t *ps)
616 {
617 return mbsnrtowcs ((wchar_t *) dest, srcp, srclen, len, ps);
618 }
619 _GL_END_C_LINKAGE
620 # else
621 _GL_FUNCDECL_SYS (mbsnrtoc32s, size_t,
622 (char32_t *dest, const char **srcp, size_t srclen, size_t len,
623 mbstate_t *ps)
624 _GL_ARG_NONNULL ((2)));
625 # endif
626 _GL_CXXALIAS_SYS (mbsnrtoc32s, size_t,
627 (char32_t *dest, const char **srcp, size_t srclen, size_t len,
628 mbstate_t *ps));
629 _GL_CXXALIASWARN (mbsnrtoc32s);
630 #endif
631
632
633 /* Convert a string to a 32-bit wide string. */
634 #if @GNULIB_MBSRTOC32S@
635 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_MBSRTOC32S
636 _GL_BEGIN_C_LINKAGE
637 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
638 mbsrtoc32s (char32_t *dest, const char **srcp, size_t len, mbstate_t *ps)
639 {
640 return mbsrtowcs ((wchar_t *) dest, srcp, len, ps);
641 }
642 _GL_END_C_LINKAGE
643 # else
644 _GL_FUNCDECL_SYS (mbsrtoc32s, size_t,
645 (char32_t *dest, const char **srcp, size_t len, mbstate_t *ps)
646 _GL_ARG_NONNULL ((2)));
647 # endif
648 _GL_CXXALIAS_SYS (mbsrtoc32s, size_t,
649 (char32_t *dest, const char **srcp, size_t len,
650 mbstate_t *ps));
651 _GL_CXXALIASWARN (mbsrtoc32s);
652 #endif
653
654
655 /* Convert a string to a 32-bit wide string. */
656 #if @GNULIB_MBSTOC32S@
657 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_MBSTOC32S
658 _GL_BEGIN_C_LINKAGE
659 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
660 mbstoc32s (char32_t *dest, const char *src, size_t len)
661 {
662 mbstate_t state;
663
664 mbszero (&state);
665 return mbsrtoc32s (dest, &src, len, &state);
666 }
667 _GL_END_C_LINKAGE
668 # else
669 _GL_FUNCDECL_SYS (mbstoc32s, size_t,
670 (char32_t *dest, const char *src, size_t len)
671 _GL_ARG_NONNULL ((2)));
672 # endif
673 _GL_CXXALIAS_SYS (mbstoc32s, size_t,
674 (char32_t *dest, const char *src, size_t len));
675 _GL_CXXALIASWARN (mbstoc32s);
676 #endif
677
678
679 #if @GNULIB_C32_GET_TYPE_TEST@ || @GNULIB_C32_APPLY_TYPE_TEST@
680 /* A scalar type. Instances of this type, other than (c32_type_test_t) 0,
681 represent a character property, sometimes also viewed as a "character class".
682 It can be applied to 32-bit wide characters. It is the counterpart of
683 type 'wctype_t' for wide characters.
684 To test whether a given character has a certain property, use the function
685 'c32_apply_type_test'. */
686 # if _GL_WCHAR_T_IS_UCS4
687 typedef wctype_t c32_type_test_t;
688 # else
689 typedef /*bool*/int (*c32_type_test_t) (wint_t wc);
690 # endif
691 #endif
692
693 /* Return a character property with the given name, or (c32_type_test_t) 0
694 if the designated property does not exist.
695 This function is the counterpart of function 'wctype' for wide characters.
696 */
697 #if @GNULIB_C32_GET_TYPE_TEST@
698 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32_GET_TYPE_TEST
699 _GL_BEGIN_C_LINKAGE
700 _GL_INLINE _GL_ARG_NONNULL ((1)) c32_type_test_t
701 c32_get_type_test (const char *name)
702 {
703 return wctype (name);
704 }
705 _GL_END_C_LINKAGE
706 # else
707 _GL_FUNCDECL_SYS (c32_get_type_test, c32_type_test_t, (const char *name)
708 _GL_ARG_NONNULL ((1)));
709 # endif
710 _GL_CXXALIAS_SYS (c32_get_type_test, c32_type_test_t, (const char *name));
711 _GL_CXXALIASWARN (c32_get_type_test);
712 #endif
713
714 /* Test whether a given 32-bit wide character has the specified character
715 property.
716 Return non-zero if true, zero if false or if the argument is WEOF.
717 This function is the counterpart of function 'iswctype' for wide characters.
718 */
719 #if @GNULIB_C32_APPLY_TYPE_TEST@
720 # if _GL_WCHAR_T_IS_UCS4
721 # if !defined IN_C32_APPLY_TYPE_TEST
722 _GL_BEGIN_C_LINKAGE
723 _GL_INLINE int
724 c32_apply_type_test (wint_t wc, c32_type_test_t property)
725 {
726 return iswctype (wc, property);
727 }
728 _GL_END_C_LINKAGE
729 # else
730 _GL_FUNCDECL_SYS (c32_apply_type_test, int,
731 (wint_t wc, c32_type_test_t property));
732 # endif
733 # else
734 _GL_FUNCDECL_SYS (c32_apply_type_test, int,
735 (wint_t wc, c32_type_test_t property)
736 _GL_ARG_NONNULL ((2)));
737 # endif
738 _GL_CXXALIAS_SYS (c32_apply_type_test, int,
739 (wint_t wc, c32_type_test_t property));
740 _GL_CXXALIASWARN (c32_apply_type_test);
741 #endif
742
743
744 #if @GNULIB_C32_GET_MAPPING@ || @GNULIB_C32_APPLY_MAPPING@
745 /* A scalar type. Instances of this type, other than (c32_mapping_t) 0,
746 represent a character mapping. It can be applied to 32-bit wide characters.
747 It is the counterpart of type 'wctrans_t' for wide characters.
748 To apply a certain mapping to a given character, use the function
749 'c32_apply_mapping'. */
750 # if _GL_WCHAR_T_IS_UCS4
751 typedef wctrans_t c32_mapping_t;
752 # else
753 typedef wint_t (*c32_mapping_t) (wint_t wc);
754 # endif
755 #endif
756
757 /* Return a character mapping with the given name, or (c32_mapping_t) 0
758 if the designated mapping does not exist.
759 This function is the counterpart of function 'wctrans' for wide characters.
760 */
761 #if @GNULIB_C32_GET_MAPPING@
762 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32_GET_MAPPING
763 _GL_BEGIN_C_LINKAGE
764 _GL_INLINE _GL_ARG_NONNULL ((1)) c32_mapping_t
765 c32_get_mapping (const char *name)
766 {
767 return wctrans (name);
768 }
769 _GL_END_C_LINKAGE
770 # else
771 _GL_FUNCDECL_SYS (c32_get_mapping, c32_mapping_t, (const char *name)
772 _GL_ARG_NONNULL ((1)));
773 # endif
774 _GL_CXXALIAS_SYS (c32_get_mapping, c32_mapping_t, (const char *name));
775 _GL_CXXALIASWARN (c32_get_mapping);
776 #endif
777
778 /* Apply the specified character mapping to a given 32-bit wide character.
779 Return the result of this mapping. Return the WC argument unchanged if it is
780 WEOF.
781 This function is the counterpart of function 'towctrans' for wide characters.
782 */
783 #if @GNULIB_C32_APPLY_MAPPING@
784 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32_APPLY_MAPPING
785 _GL_BEGIN_C_LINKAGE
786 _GL_INLINE _GL_ARG_NONNULL ((2)) wint_t
787 c32_apply_mapping (wint_t wc, c32_mapping_t mapping)
788 {
789 return towctrans (wc, mapping);
790 }
791 _GL_END_C_LINKAGE
792 # else
793 _GL_FUNCDECL_SYS (c32_apply_mapping, wint_t,
794 (wint_t wc, c32_mapping_t mapping)
795 _GL_ARG_NONNULL ((2)));
796 # endif
797 _GL_CXXALIAS_SYS (c32_apply_mapping, wint_t,
798 (wint_t wc, c32_mapping_t mapping));
799 _GL_CXXALIASWARN (c32_apply_mapping);
800 #endif
801
802
803 _GL_INLINE_HEADER_END
804
805 #endif /* _@GUARD_PREFIX@_UCHAR_H */
806 #endif /* _@GUARD_PREFIX@_UCHAR_H */