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 #define _@GUARD_PREFIX@_UCHAR_H
25
26 #if __GNUC__ >= 3
27 @PRAGMA_SYSTEM_HEADER@
28 #endif
29 @PRAGMA_COLUMNS@
30
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 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_BEGIN_C_LINKAGE,
48 _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
49 #if !_GL_CONFIG_H_INCLUDED
50 #error "Please include config.h first."
51 #endif
52
53 /* Get uint_least16_t, uint_least32_t. */
54 #include <stdint.h>
55
56 /* Get mbstate_t, size_t. */
57 #include <wchar.h>
58
59 /* For the inline functions. */
60 #include <string.h>
61 #include <wctype.h>
62
63 /* The __attribute__ feature is available in gcc versions 2.5 and later.
64 The attribute __pure__ was added in gcc 2.96. */
65 #ifndef _GL_ATTRIBUTE_PURE
66 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
67 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
68 # else
69 # define _GL_ATTRIBUTE_PURE /* empty */
70 # endif
71 #endif
72
73 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
74
75
76 _GL_INLINE_HEADER_BEGIN
77
78
79 #if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_CHAR8_TYPE@))
80
81 /* An 8-bit variant of wchar_t.
82 Note: This type is only mandated by ISO C 23 or newer, and it does
83 denote UTF-8 units. */
84 typedef unsigned char char8_t;
85
86 #elif @GNULIBHEADERS_OVERRIDE_CHAR8_T@
87
88 typedef unsigned char gl_char8_t;
89 # define char8_t gl_char8_t
90
91 #endif
92
93 #if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_UCHAR_TYPES@))
94
95 /* A 16-bit variant of wchar_t.
96 Note: This type is only mandated by ISO C 11 or newer. In ISO C 23
97 and newer, it denotes UTF-16 units; in older versions of ISO C it did
98 so only on platforms on which __STDC_UTF_16__ was defined. */
99 typedef uint_least16_t char16_t;
100
101 #elif @GNULIBHEADERS_OVERRIDE_CHAR16_T@
102
103 typedef uint_least16_t gl_char16_t;
104 # define char16_t gl_char16_t
105
106 #endif
107
108 #if !(@HAVE_UCHAR_H@ || (defined __cplusplus && @CXX_HAS_UCHAR_TYPES@))
109
110 /* A 32-bit variant of wchar_t.
111 Note: This type is only mandated by ISO C 11 or newer. In ISO C 23
112 and newer, it denotes UTF-32 code points; in older versions of ISO C
113 it did so only on platforms on which __STDC_UTF_32__ was defined.
114 In gnulib, we guarantee that it denotes UTF-32 code points if and
115 only if the module 'uchar-c23' is in use. */
116 typedef uint_least32_t char32_t;
117
118 #elif @GNULIBHEADERS_OVERRIDE_CHAR32_T@
119
120 typedef uint_least32_t gl_char32_t;
121 # define char32_t gl_char32_t
122
123 #endif
124
125 /* Define if a 'char32_t' can hold more characters than a 'wchar_t'. */
126 #if @SMALL_WCHAR_T@ /* 32-bit AIX, Cygwin, native Windows */
127 # define _GL_SMALL_WCHAR_T 1
128 #endif
129
130 /* Define if 'wchar_t', like 'char32_t',
131 - is a 32-bit type, and
132 - represents Unicode code points.
133 For this test, we can use __STDC_ISO_10646__ (defined by glibc, musl libc,
134 Cygwin) but need to consider _GL_SMALL_WCHAR_T, so as to exclude Cygwin.
135 We cannot use __STDC_UTF_16__ or __STDC_UTF_32__
136 - because these macros provide info about char16_t and char32_t (not
137 wchar_t!), and
138 - because GCC >= 4.9 defines these macros on all platforms, even on
139 FreeBSD and Solaris.
140 We should better not use __STD_UTF_16__, __STD_UTF_32__ either, because
141 these macros are misspellings, only defined by Android's <uchar.h>. */
142 #if defined __STDC_ISO_10646__ && !_GL_SMALL_WCHAR_T
143 /* glibc, musl libc */
144 # define _GL_WCHAR_T_IS_UCS4 1
145 #endif
146 #if _GL_WCHAR_T_IS_UCS4
147 static_assert (sizeof (char32_t) == sizeof (wchar_t));
148 #endif
149
150
151 /* Convert a single-byte character to a 32-bit wide character. */
152 #if @GNULIB_BTOC32@
153 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_BTOC32
154 _GL_BEGIN_C_LINKAGE
155 _GL_INLINE _GL_ATTRIBUTE_PURE wint_t
156 btoc32 (int c)
157 {
158 return btowc (c);
159 }
160 _GL_END_C_LINKAGE
161 # else
162 _GL_FUNCDECL_SYS (btoc32, wint_t, (int c) _GL_ATTRIBUTE_PURE);
163 # endif
164 _GL_CXXALIAS_SYS (btoc32, wint_t, (int c));
165 _GL_CXXALIASWARN (btoc32);
166 #endif
167
168
169 /* Test a specific property of a 32-bit wide character. */
170 #if @GNULIB_C32ISALNUM@
171 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISALNUM
172 _GL_BEGIN_C_LINKAGE
173 _GL_INLINE int
174 c32isalnum (wint_t wc)
175 {
176 return iswalnum (wc);
177 }
178 _GL_END_C_LINKAGE
179 # else
180 _GL_FUNCDECL_SYS (c32isalnum, int, (wint_t wc));
181 # endif
182 _GL_CXXALIAS_SYS (c32isalnum, int, (wint_t wc));
183 _GL_CXXALIASWARN (c32isalnum);
184 #endif
185 #if @GNULIB_C32ISALPHA@
186 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISALPHA
187 _GL_BEGIN_C_LINKAGE
188 _GL_INLINE int
189 c32isalpha (wint_t wc)
190 {
191 return iswalpha (wc);
192 }
193 _GL_END_C_LINKAGE
194 # else
195 _GL_FUNCDECL_SYS (c32isalpha, int, (wint_t wc));
196 # endif
197 _GL_CXXALIAS_SYS (c32isalpha, int, (wint_t wc));
198 _GL_CXXALIASWARN (c32isalpha);
199 #endif
200 #if @GNULIB_C32ISBLANK@
201 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISBLANK
202 _GL_BEGIN_C_LINKAGE
203 _GL_INLINE int
204 c32isblank (wint_t wc)
205 {
206 return iswblank (wc);
207 }
208 _GL_END_C_LINKAGE
209 # else
210 _GL_FUNCDECL_SYS (c32isblank, int, (wint_t wc));
211 # endif
212 _GL_CXXALIAS_SYS (c32isblank, int, (wint_t wc));
213 _GL_CXXALIASWARN (c32isblank);
214 #endif
215 #if @GNULIB_C32ISCNTRL@
216 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISCNTRL
217 _GL_BEGIN_C_LINKAGE
218 _GL_INLINE int
219 c32iscntrl (wint_t wc)
220 {
221 return iswcntrl (wc);
222 }
223 _GL_END_C_LINKAGE
224 # else
225 _GL_FUNCDECL_SYS (c32iscntrl, int, (wint_t wc));
226 # endif
227 _GL_CXXALIAS_SYS (c32iscntrl, int, (wint_t wc));
228 _GL_CXXALIASWARN (c32iscntrl);
229 #endif
230 #if @GNULIB_C32ISDIGIT@
231 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISDIGIT
232 _GL_BEGIN_C_LINKAGE
233 _GL_INLINE int
234 c32isdigit (wint_t wc)
235 {
236 return iswdigit (wc);
237 }
238 _GL_END_C_LINKAGE
239 # else
240 _GL_FUNCDECL_SYS (c32isdigit, int, (wint_t wc));
241 # endif
242 _GL_CXXALIAS_SYS (c32isdigit, int, (wint_t wc));
243 _GL_CXXALIASWARN (c32isdigit);
244 #endif
245 #if @GNULIB_C32ISGRAPH@
246 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISGRAPH
247 _GL_BEGIN_C_LINKAGE
248 _GL_INLINE int
249 c32isgraph (wint_t wc)
250 {
251 return iswgraph (wc);
252 }
253 _GL_END_C_LINKAGE
254 # else
255 _GL_FUNCDECL_SYS (c32isgraph, int, (wint_t wc));
256 # endif
257 _GL_CXXALIAS_SYS (c32isgraph, int, (wint_t wc));
258 _GL_CXXALIASWARN (c32isgraph);
259 #endif
260 #if @GNULIB_C32ISLOWER@
261 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISLOWER
262 _GL_BEGIN_C_LINKAGE
263 _GL_INLINE int
264 c32islower (wint_t wc)
265 {
266 return iswlower (wc);
267 }
268 _GL_END_C_LINKAGE
269 # else
270 _GL_FUNCDECL_SYS (c32islower, int, (wint_t wc));
271 # endif
272 _GL_CXXALIAS_SYS (c32islower, int, (wint_t wc));
273 _GL_CXXALIASWARN (c32islower);
274 #endif
275 #if @GNULIB_C32ISPRINT@
276 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISPRINT
277 _GL_BEGIN_C_LINKAGE
278 _GL_INLINE int
279 c32isprint (wint_t wc)
280 {
281 return iswprint (wc);
282 }
283 _GL_END_C_LINKAGE
284 # else
285 _GL_FUNCDECL_SYS (c32isprint, int, (wint_t wc));
286 # endif
287 _GL_CXXALIAS_SYS (c32isprint, int, (wint_t wc));
288 _GL_CXXALIASWARN (c32isprint);
289 #endif
290 #if @GNULIB_C32ISPUNCT@
291 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISPUNCT
292 _GL_BEGIN_C_LINKAGE
293 _GL_INLINE int
294 c32ispunct (wint_t wc)
295 {
296 return iswpunct (wc);
297 }
298 _GL_END_C_LINKAGE
299 # else
300 _GL_FUNCDECL_SYS (c32ispunct, int, (wint_t wc));
301 # endif
302 _GL_CXXALIAS_SYS (c32ispunct, int, (wint_t wc));
303 _GL_CXXALIASWARN (c32ispunct);
304 #endif
305 #if @GNULIB_C32ISSPACE@
306 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISSPACE
307 _GL_BEGIN_C_LINKAGE
308 _GL_INLINE int
309 c32isspace (wint_t wc)
310 {
311 return iswspace (wc);
312 }
313 _GL_END_C_LINKAGE
314 # else
315 _GL_FUNCDECL_SYS (c32isspace, int, (wint_t wc));
316 # endif
317 _GL_CXXALIAS_SYS (c32isspace, int, (wint_t wc));
318 _GL_CXXALIASWARN (c32isspace);
319 #endif
320 #if @GNULIB_C32ISUPPER@
321 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISUPPER
322 _GL_BEGIN_C_LINKAGE
323 _GL_INLINE int
324 c32isupper (wint_t wc)
325 {
326 return iswupper (wc);
327 }
328 _GL_END_C_LINKAGE
329 # else
330 _GL_FUNCDECL_SYS (c32isupper, int, (wint_t wc));
331 # endif
332 _GL_CXXALIAS_SYS (c32isupper, int, (wint_t wc));
333 _GL_CXXALIASWARN (c32isupper);
334 #endif
335 #if @GNULIB_C32ISXDIGIT@
336 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISXDIGIT
337 _GL_BEGIN_C_LINKAGE
338 _GL_INLINE int
339 c32isxdigit (wint_t wc)
340 {
341 return iswxdigit (wc);
342 }
343 _GL_END_C_LINKAGE
344 # else
345 _GL_FUNCDECL_SYS (c32isxdigit, int, (wint_t wc));
346 # endif
347 _GL_CXXALIAS_SYS (c32isxdigit, int, (wint_t wc));
348 _GL_CXXALIASWARN (c32isxdigit);
349 #endif
350
351
352 /* Case mapping of a 32-bit wide character. */
353 #if @GNULIB_C32TOLOWER@
354 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32TOLOWER
355 _GL_BEGIN_C_LINKAGE
356 _GL_INLINE wint_t
357 c32tolower (wint_t wc)
358 {
359 return towlower (wc);
360 }
361 _GL_END_C_LINKAGE
362 # else
363 _GL_FUNCDECL_SYS (c32tolower, wint_t, (wint_t wc));
364 # endif
365 _GL_CXXALIAS_SYS (c32tolower, wint_t, (wint_t wc));
366 _GL_CXXALIASWARN (c32tolower);
367 #endif
368 #if @GNULIB_C32TOUPPER@
369 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32TOUPPER
370 _GL_BEGIN_C_LINKAGE
371 _GL_INLINE wint_t
372 c32toupper (wint_t wc)
373 {
374 return towupper (wc);
375 }
376 _GL_END_C_LINKAGE
377 # else
378 _GL_FUNCDECL_SYS (c32toupper, wint_t, (wint_t wc));
379 # endif
380 _GL_CXXALIAS_SYS (c32toupper, wint_t, (wint_t wc));
381 _GL_CXXALIASWARN (c32toupper);
382 #endif
383
384
385 /* Number of screen columns needed for a 32-bit wide character. */
386 #if @GNULIB_C32WIDTH@
387 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32WIDTH
388 _GL_BEGIN_C_LINKAGE
389 _GL_INLINE int
390 c32width (char32_t wc)
391 {
392 return wcwidth (wc);
393 }
394 _GL_END_C_LINKAGE
395 # else
396 _GL_FUNCDECL_SYS (c32width, int, (char32_t wc));
397 # endif
398 _GL_CXXALIAS_SYS (c32width, int, (char32_t wc));
399 _GL_CXXALIASWARN (c32width);
400 #endif
401
402
403 /* Converts a 32-bit wide character to a multibyte character. */
404 #if @GNULIB_C32RTOMB@
405 # if @REPLACE_C32RTOMB@
406 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
407 # undef c32rtomb
408 # define c32rtomb rpl_c32rtomb
409 # endif
410 _GL_FUNCDECL_RPL (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
411 _GL_CXXALIAS_RPL (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
412 # else
413 # if !@HAVE_C32RTOMB@
414 _GL_FUNCDECL_SYS (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
415 # endif
416 _GL_CXXALIAS_SYS (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
417 # endif
418 # if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
419 _GL_CXXALIASWARN (c32rtomb);
420 # endif
421 #elif defined GNULIB_POSIXCHECK
422 # undef c32rtomb
423 # if HAVE_RAW_DECL_C32RTOMB
424 _GL_WARN_ON_USE (c32rtomb, "c32rtomb is not portable - "
425 "use gnulib module c32rtomb for portability");
426 # endif
427 #endif
428
429
430 /* Convert a 32-bit wide string to a string. */
431 #if @GNULIB_C32SNRTOMBS@
432 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32SNRTOMBS
433 _GL_BEGIN_C_LINKAGE
434 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
435 c32snrtombs (char *dest, const char32_t **srcp, size_t srclen, size_t len,
436 mbstate_t *ps)
437 {
438 return wcsnrtombs (dest, (const wchar_t **) srcp, srclen, len, ps);
439 }
440 _GL_END_C_LINKAGE
441 # else
442 _GL_FUNCDECL_SYS (c32snrtombs, size_t,
443 (char *dest, const char32_t **srcp, size_t srclen, size_t len,
444 mbstate_t *ps)
445 _GL_ARG_NONNULL ((2)));
446 # endif
447 _GL_CXXALIAS_SYS (c32snrtombs, size_t,
448 (char *dest, const char32_t **srcp, size_t srclen, size_t len,
449 mbstate_t *ps));
450 _GL_CXXALIASWARN (c32snrtombs);
451 #endif
452
453
454 /* Convert a 32-bit wide string to a string. */
455 #if @GNULIB_C32SRTOMBS@
456 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32SRTOMBS
457 _GL_BEGIN_C_LINKAGE
458 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
459 c32srtombs (char *dest, const char32_t **srcp, size_t len, mbstate_t *ps)
460 {
461 return wcsrtombs (dest, (const wchar_t **) srcp, len, ps);
462 }
463 _GL_END_C_LINKAGE
464 # else
465 _GL_FUNCDECL_SYS (c32srtombs, size_t,
466 (char *dest, const char32_t **srcp, size_t len, mbstate_t *ps)
467 _GL_ARG_NONNULL ((2)));
468 # endif
469 _GL_CXXALIAS_SYS (c32srtombs, size_t,
470 (char *dest, const char32_t **srcp, size_t len,
471 mbstate_t *ps));
472 _GL_CXXALIASWARN (c32srtombs);
473 #endif
474
475
476 /* Convert a 32-bit wide string to a string. */
477 #if @GNULIB_C32STOMBS@
478 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32STOMBS
479 _GL_BEGIN_C_LINKAGE
480 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
481 c32stombs (char *dest, const char32_t *src, size_t len)
482 {
483 mbstate_t state;
484
485 memset (&state, '\0', sizeof (mbstate_t));
486 return c32srtombs (dest, &src, len, &state);
487 }
488 _GL_END_C_LINKAGE
489 # else
490 _GL_FUNCDECL_SYS (c32stombs, size_t,
491 (char *dest, const char32_t *src, size_t len)
492 _GL_ARG_NONNULL ((2)));
493 # endif
494 _GL_CXXALIAS_SYS (c32stombs, size_t,
495 (char *dest, const char32_t *src, size_t len));
496 _GL_CXXALIASWARN (c32stombs);
497 #endif
498
499
500 /* Number of screen columns needed for a size-bounded 32-bit wide string. */
501 #if @GNULIB_C32SWIDTH@
502 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32SWIDTH
503 _GL_BEGIN_C_LINKAGE
504 _GL_INLINE _GL_ARG_NONNULL ((1)) int
505 c32swidth (const char32_t *s, size_t n)
506 {
507 return wcswidth ((const wchar_t *) s, n);
508 }
509 _GL_END_C_LINKAGE
510 # else
511 _GL_FUNCDECL_SYS (c32swidth, int, (const char32_t *s, size_t n)
512 _GL_ARG_NONNULL ((1)));
513 # endif
514 _GL_CXXALIAS_SYS (c32swidth, int, (const char32_t *s, size_t n));
515 _GL_CXXALIASWARN (c32swidth);
516 #endif
517
518
519 /* Converts a 32-bit wide character to unibyte character.
520 Returns the single-byte representation of WC if it exists,
521 or EOF otherwise. */
522 #if @GNULIB_C32TOB@
523 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32TOB
524 _GL_BEGIN_C_LINKAGE
525 _GL_INLINE int
526 c32tob (wint_t wc)
527 {
528 return wctob (wc);
529 }
530 _GL_END_C_LINKAGE
531 # else
532 _GL_FUNCDECL_SYS (c32tob, int, (wint_t wc));
533 # endif
534 _GL_CXXALIAS_SYS (c32tob, int, (wint_t wc));
535 _GL_CXXALIASWARN (c32tob);
536 #endif
537
538
539 /* Converts a multibyte character to a 32-bit wide character. */
540 #if @GNULIB_MBRTOC32@
541 # if @REPLACE_MBRTOC32@
542 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
543 # undef mbrtoc32
544 # define mbrtoc32 rpl_mbrtoc32
545 # endif
546 _GL_FUNCDECL_RPL (mbrtoc32, size_t,
547 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
548 _GL_CXXALIAS_RPL (mbrtoc32, size_t,
549 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
550 # else
551 # if !@HAVE_MBRTOC32@
552 _GL_FUNCDECL_SYS (mbrtoc32, size_t,
553 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
554 # endif
555 _GL_CXXALIAS_SYS (mbrtoc32, size_t,
556 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
557 # endif
558 # if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
559 _GL_CXXALIASWARN (mbrtoc32);
560 # endif
561 #elif defined GNULIB_POSIXCHECK
562 # undef mbrtoc32
563 # if HAVE_RAW_DECL_MBRTOC32
564 _GL_WARN_ON_USE (mbrtoc32, "mbrtoc32 is not portable - "
565 "use gnulib module mbrtoc32 for portability");
566 # endif
567 #endif
568
569
570 /* Converts a multibyte character and returns the next 16-bit wide
571 character. */
572 #if @GNULIB_MBRTOC16@
573 # if @REPLACE_MBRTOC16@
574 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
575 # undef mbrtoc16
576 # define mbrtoc16 rpl_mbrtoc16
577 # endif
578 _GL_FUNCDECL_RPL (mbrtoc16, size_t,
579 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
580 _GL_CXXALIAS_RPL (mbrtoc16, size_t,
581 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
582 # else
583 # if !@HAVE_MBRTOC32@
584 _GL_FUNCDECL_SYS (mbrtoc16, size_t,
585 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
586 # endif
587 _GL_CXXALIAS_SYS (mbrtoc16, size_t,
588 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
589 # endif
590 # if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
591 _GL_CXXALIASWARN (mbrtoc16);
592 # endif
593 #elif defined GNULIB_POSIXCHECK
594 # undef mbrtoc16
595 # if HAVE_RAW_DECL_MBRTOC16
596 _GL_WARN_ON_USE (mbrtoc16, "mbrtoc16 is not portable - "
597 "use gnulib module mbrtoc16 for portability");
598 # endif
599 #endif
600
601
602 /* Convert a string to a 32-bit wide string. */
603 #if @GNULIB_MBSNRTOC32S@
604 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_MBSNRTOC32S
605 _GL_BEGIN_C_LINKAGE
606 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
607 mbsnrtoc32s (char32_t *dest, const char **srcp, size_t srclen, size_t len,
608 mbstate_t *ps)
609 {
610 return mbsnrtowcs ((wchar_t *) dest, srcp, srclen, len, ps);
611 }
612 _GL_END_C_LINKAGE
613 # else
614 _GL_FUNCDECL_SYS (mbsnrtoc32s, size_t,
615 (char32_t *dest, const char **srcp, size_t srclen, size_t len,
616 mbstate_t *ps)
617 _GL_ARG_NONNULL ((2)));
618 # endif
619 _GL_CXXALIAS_SYS (mbsnrtoc32s, size_t,
620 (char32_t *dest, const char **srcp, size_t srclen, size_t len,
621 mbstate_t *ps));
622 _GL_CXXALIASWARN (mbsnrtoc32s);
623 #endif
624
625
626 /* Convert a string to a 32-bit wide string. */
627 #if @GNULIB_MBSRTOC32S@
628 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_MBSRTOC32S
629 _GL_BEGIN_C_LINKAGE
630 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
631 mbsrtoc32s (char32_t *dest, const char **srcp, size_t len, mbstate_t *ps)
632 {
633 return mbsrtowcs ((wchar_t *) dest, srcp, len, ps);
634 }
635 _GL_END_C_LINKAGE
636 # else
637 _GL_FUNCDECL_SYS (mbsrtoc32s, size_t,
638 (char32_t *dest, const char **srcp, size_t len, mbstate_t *ps)
639 _GL_ARG_NONNULL ((2)));
640 # endif
641 _GL_CXXALIAS_SYS (mbsrtoc32s, size_t,
642 (char32_t *dest, const char **srcp, size_t len,
643 mbstate_t *ps));
644 _GL_CXXALIASWARN (mbsrtoc32s);
645 #endif
646
647
648 /* Convert a string to a 32-bit wide string. */
649 #if @GNULIB_MBSTOC32S@
650 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_MBSTOC32S
651 _GL_BEGIN_C_LINKAGE
652 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
653 mbstoc32s (char32_t *dest, const char *src, size_t len)
654 {
655 mbstate_t state;
656
657 memset (&state, '\0', sizeof (mbstate_t));
658 return mbsrtoc32s (dest, &src, len, &state);
659 }
660 _GL_END_C_LINKAGE
661 # else
662 _GL_FUNCDECL_SYS (mbstoc32s, size_t,
663 (char32_t *dest, const char *src, size_t len)
664 _GL_ARG_NONNULL ((2)));
665 # endif
666 _GL_CXXALIAS_SYS (mbstoc32s, size_t,
667 (char32_t *dest, const char *src, size_t len));
668 _GL_CXXALIASWARN (mbstoc32s);
669 #endif
670
671
672 _GL_INLINE_HEADER_END
673
674 #endif /* _@GUARD_PREFIX@_UCHAR_H */