1 /* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
3 Copyright (C) 2007-2020 Free Software Foundation, Inc.
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, or (at your option)
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.
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/>. */
18 /* Written by Eric Blake. */
21 * ISO C 99 <wchar.h> for platforms that have issues.
22 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/wchar.h.html>
24 * For now, this just ensures proper prerequisite inclusion order and
25 * the declaration of wcwidth().
29 @PRAGMA_SYSTEM_HEADER@
33 #if (((defined __need_mbstate_t || defined __need_wint_t) \
34 && !defined __MINGW32__) \
36 && ((defined _INTTYPES_INCLUDED \
37 && !defined _GL_FINISHED_INCLUDING_SYSTEM_INTTYPES_H) \
38 || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) \
39 || (defined __MINGW32__ && defined __STRING_H_SOURCED__) \
40 || defined _GL_ALREADY_INCLUDING_WCHAR_H)
41 /* Special invocation convention:
42 - Inside glibc and uClibc header files, but not MinGW.
43 - On HP-UX 11.00 we have a sequence of nested includes
44 <wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>,
45 once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h>
46 and once directly. In both situations 'wint_t' is not yet defined,
47 therefore we cannot provide the function overrides; instead include only
48 the system's <wchar.h>.
49 - With MinGW 3.22, when <string.h> includes <wchar.h>, only some part of
50 <wchar.h> is actually processed, and that doesn't include 'mbstate_t'.
51 - On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and
52 the latter includes <wchar.h>. But here, we have no way to detect whether
53 <wctype.h> is completely included or is still being included. */
55 #@INCLUDE_NEXT@ @NEXT_WCHAR_H@
58 /* Normal invocation convention. */
60 #ifndef _@GUARD_PREFIX@_WCHAR_H
62 #define _GL_ALREADY_INCLUDING_WCHAR_H
65 # include <features.h> /* for __GLIBC__ */
68 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
70 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
71 included before <wchar.h>.
72 In some builds of uClibc, <wchar.h> is nonexistent and wchar_t is defined
74 But avoid namespace pollution on glibc systems. */
75 #if !(defined __GLIBC__ && !defined __UCLIBC__)
83 /* Include the original <wchar.h> if it exists.
84 Some builds of uClibc lack it. */
85 /* The include_next requires a split double-inclusion guard. */
87 # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
90 #undef _GL_ALREADY_INCLUDING_WCHAR_H
92 #ifndef _@GUARD_PREFIX@_WCHAR_H
93 #define _@GUARD_PREFIX@_WCHAR_H
95 /* The __attribute__ feature is available in gcc versions 2.5 and later.
96 The attribute __pure__ was added in gcc 2.96. */
97 #ifndef _GL_ATTRIBUTE_PURE
98 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
99 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
101 # define _GL_ATTRIBUTE_PURE /* empty */
105 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
107 /* The definition of _GL_ARG_NONNULL is copied here. */
109 /* The definition of _GL_WARN_ON_USE is copied here. */
112 /* Define wint_t and WEOF. (Also done in wctype.in.h.) */
113 #if !@HAVE_WINT_T@ && !defined wint_t
119 /* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h> or
120 <stddef.h>. This is too small: ISO C 99 section 7.24.1.(2) says that
121 wint_t must be "unchanged by default argument promotions". Override it. */
122 # if @GNULIB_OVERRIDES_WINT_T@
123 # if !GNULIB_defined_wint_t
124 # if @HAVE_CRTDEFS_H@
125 # include <crtdefs.h>
129 typedef unsigned int rpl_wint_t
;
131 # define wint_t rpl_wint_t
132 # define GNULIB_defined_wint_t 1
136 # define WEOF ((wint_t) -1)
141 /* Override mbstate_t if it is too small.
142 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
143 implementing mbrtowc for encodings like UTF-8.
144 On AIX and MSVC, mbrtowc needs to be overridden, but mbstate_t exists and is
145 large enough and overriding it would cause problems in C++ mode. */
146 #if !(((defined _WIN32 && !defined __CYGWIN__) || @HAVE_MBSINIT@) && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
147 # if !GNULIB_defined_mbstate_t
148 # if !(defined _AIX || defined _MSC_VER)
149 typedef int rpl_mbstate_t
;
151 # define mbstate_t rpl_mbstate_t
153 # define GNULIB_defined_mbstate_t 1
158 /* Convert a single-byte character to a wide character. */
161 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
163 # define btowc rpl_btowc
165 _GL_FUNCDECL_RPL (btowc
, wint_t, (int c
) _GL_ATTRIBUTE_PURE
);
166 _GL_CXXALIAS_RPL (btowc
, wint_t, (int c
));
169 _GL_FUNCDECL_SYS (btowc
, wint_t, (int c
) _GL_ATTRIBUTE_PURE
);
171 /* Need to cast, because on mingw, the return type is 'unsigned short'. */
172 _GL_CXXALIAS_SYS_CAST (btowc
, wint_t, (int c
));
175 _GL_CXXALIASWARN (btowc
);
177 #elif defined GNULIB_POSIXCHECK
179 # if HAVE_RAW_DECL_BTOWC
180 _GL_WARN_ON_USE (btowc
, "btowc is unportable - "
181 "use gnulib module btowc for portability");
186 /* Convert a wide character to a single-byte character. */
189 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
191 # define wctob rpl_wctob
193 _GL_FUNCDECL_RPL (wctob
, int, (wint_t wc
) _GL_ATTRIBUTE_PURE
);
194 _GL_CXXALIAS_RPL (wctob
, int, (wint_t wc
));
196 # if !defined wctob && !@HAVE_DECL_WCTOB@
197 /* wctob is provided by gnulib, or wctob exists but is not declared. */
198 _GL_FUNCDECL_SYS (wctob
, int, (wint_t wc
) _GL_ATTRIBUTE_PURE
);
200 _GL_CXXALIAS_SYS (wctob
, int, (wint_t wc
));
203 _GL_CXXALIASWARN (wctob
);
205 #elif defined GNULIB_POSIXCHECK
207 # if HAVE_RAW_DECL_WCTOB
208 _GL_WARN_ON_USE (wctob
, "wctob is unportable - "
209 "use gnulib module wctob for portability");
214 /* Test whether *PS is in the initial state. */
216 # if @REPLACE_MBSINIT@
217 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
219 # define mbsinit rpl_mbsinit
221 _GL_FUNCDECL_RPL (mbsinit
, int, (const mbstate_t *ps
));
222 _GL_CXXALIAS_RPL (mbsinit
, int, (const mbstate_t *ps
));
225 _GL_FUNCDECL_SYS (mbsinit
, int, (const mbstate_t *ps
));
227 _GL_CXXALIAS_SYS (mbsinit
, int, (const mbstate_t *ps
));
230 _GL_CXXALIASWARN (mbsinit
);
232 #elif defined GNULIB_POSIXCHECK
234 # if HAVE_RAW_DECL_MBSINIT
235 _GL_WARN_ON_USE (mbsinit
, "mbsinit is unportable - "
236 "use gnulib module mbsinit for portability");
241 /* Convert a multibyte character to a wide character. */
243 # if @REPLACE_MBRTOWC@
244 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
246 # define mbrtowc rpl_mbrtowc
248 _GL_FUNCDECL_RPL (mbrtowc
, size_t,
249 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
,
250 mbstate_t *restrict ps
));
251 _GL_CXXALIAS_RPL (mbrtowc
, size_t,
252 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
,
253 mbstate_t *restrict ps
));
256 _GL_FUNCDECL_SYS (mbrtowc
, size_t,
257 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
,
258 mbstate_t *restrict ps
));
260 _GL_CXXALIAS_SYS (mbrtowc
, size_t,
261 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
,
262 mbstate_t *restrict ps
));
265 _GL_CXXALIASWARN (mbrtowc
);
267 #elif defined GNULIB_POSIXCHECK
269 # if HAVE_RAW_DECL_MBRTOWC
270 _GL_WARN_ON_USE (mbrtowc
, "mbrtowc is unportable - "
271 "use gnulib module mbrtowc for portability");
276 /* Recognize a multibyte character. */
278 # if @REPLACE_MBRLEN@
279 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
281 # define mbrlen rpl_mbrlen
283 _GL_FUNCDECL_RPL (mbrlen
, size_t,
284 (const char *restrict s
, size_t n
, mbstate_t *restrict ps
));
285 _GL_CXXALIAS_RPL (mbrlen
, size_t,
286 (const char *restrict s
, size_t n
, mbstate_t *restrict ps
));
289 _GL_FUNCDECL_SYS (mbrlen
, size_t,
290 (const char *restrict s
, size_t n
, mbstate_t *restrict ps
));
292 _GL_CXXALIAS_SYS (mbrlen
, size_t,
293 (const char *restrict s
, size_t n
, mbstate_t *restrict ps
));
296 _GL_CXXALIASWARN (mbrlen
);
298 #elif defined GNULIB_POSIXCHECK
300 # if HAVE_RAW_DECL_MBRLEN
301 _GL_WARN_ON_USE (mbrlen
, "mbrlen is unportable - "
302 "use gnulib module mbrlen for portability");
307 /* Convert a string to a wide string. */
308 #if @GNULIB_MBSRTOWCS@
309 # if @REPLACE_MBSRTOWCS@
310 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
312 # define mbsrtowcs rpl_mbsrtowcs
314 _GL_FUNCDECL_RPL (mbsrtowcs
, size_t,
315 (wchar_t *restrict dest
,
316 const char **restrict srcp
, size_t len
,
317 mbstate_t *restrict ps
)
318 _GL_ARG_NONNULL ((2)));
319 _GL_CXXALIAS_RPL (mbsrtowcs
, size_t,
320 (wchar_t *restrict dest
,
321 const char **restrict srcp
, size_t len
,
322 mbstate_t *restrict ps
));
324 # if !@HAVE_MBSRTOWCS@
325 _GL_FUNCDECL_SYS (mbsrtowcs
, size_t,
326 (wchar_t *restrict dest
,
327 const char **restrict srcp
, size_t len
,
328 mbstate_t *restrict ps
)
329 _GL_ARG_NONNULL ((2)));
331 _GL_CXXALIAS_SYS (mbsrtowcs
, size_t,
332 (wchar_t *restrict dest
,
333 const char **restrict srcp
, size_t len
,
334 mbstate_t *restrict ps
));
337 _GL_CXXALIASWARN (mbsrtowcs
);
339 #elif defined GNULIB_POSIXCHECK
341 # if HAVE_RAW_DECL_MBSRTOWCS
342 _GL_WARN_ON_USE (mbsrtowcs
, "mbsrtowcs is unportable - "
343 "use gnulib module mbsrtowcs for portability");
348 /* Convert a string to a wide string. */
349 #if @GNULIB_MBSNRTOWCS@
350 # if @REPLACE_MBSNRTOWCS@
351 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
353 # define mbsnrtowcs rpl_mbsnrtowcs
355 _GL_FUNCDECL_RPL (mbsnrtowcs
, size_t,
356 (wchar_t *restrict dest
,
357 const char **restrict srcp
, size_t srclen
, size_t len
,
358 mbstate_t *restrict ps
)
359 _GL_ARG_NONNULL ((2)));
360 _GL_CXXALIAS_RPL (mbsnrtowcs
, size_t,
361 (wchar_t *restrict dest
,
362 const char **restrict srcp
, size_t srclen
, size_t len
,
363 mbstate_t *restrict ps
));
365 # if !@HAVE_MBSNRTOWCS@
366 _GL_FUNCDECL_SYS (mbsnrtowcs
, size_t,
367 (wchar_t *restrict dest
,
368 const char **restrict srcp
, size_t srclen
, size_t len
,
369 mbstate_t *restrict ps
)
370 _GL_ARG_NONNULL ((2)));
372 _GL_CXXALIAS_SYS (mbsnrtowcs
, size_t,
373 (wchar_t *restrict dest
,
374 const char **restrict srcp
, size_t srclen
, size_t len
,
375 mbstate_t *restrict ps
));
377 _GL_CXXALIASWARN (mbsnrtowcs
);
378 #elif defined GNULIB_POSIXCHECK
380 # if HAVE_RAW_DECL_MBSNRTOWCS
381 _GL_WARN_ON_USE (mbsnrtowcs
, "mbsnrtowcs is unportable - "
382 "use gnulib module mbsnrtowcs for portability");
387 /* Convert a wide character to a multibyte character. */
389 # if @REPLACE_WCRTOMB@
390 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
392 # define wcrtomb rpl_wcrtomb
394 _GL_FUNCDECL_RPL (wcrtomb
, size_t,
395 (char *restrict s
, wchar_t wc
, mbstate_t *restrict ps
));
396 _GL_CXXALIAS_RPL (wcrtomb
, size_t,
397 (char *restrict s
, wchar_t wc
, mbstate_t *restrict ps
));
400 _GL_FUNCDECL_SYS (wcrtomb
, size_t,
401 (char *restrict s
, wchar_t wc
, mbstate_t *restrict ps
));
403 _GL_CXXALIAS_SYS (wcrtomb
, size_t,
404 (char *restrict s
, wchar_t wc
, mbstate_t *restrict ps
));
407 _GL_CXXALIASWARN (wcrtomb
);
409 #elif defined GNULIB_POSIXCHECK
411 # if HAVE_RAW_DECL_WCRTOMB
412 _GL_WARN_ON_USE (wcrtomb
, "wcrtomb is unportable - "
413 "use gnulib module wcrtomb for portability");
418 /* Convert a wide string to a string. */
419 #if @GNULIB_WCSRTOMBS@
420 # if @REPLACE_WCSRTOMBS@
421 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
423 # define wcsrtombs rpl_wcsrtombs
425 _GL_FUNCDECL_RPL (wcsrtombs
, size_t,
426 (char *restrict dest
, const wchar_t **restrict srcp
,
428 mbstate_t *restrict ps
)
429 _GL_ARG_NONNULL ((2)));
430 _GL_CXXALIAS_RPL (wcsrtombs
, size_t,
431 (char *restrict dest
, const wchar_t **restrict srcp
,
433 mbstate_t *restrict ps
));
435 # if !@HAVE_WCSRTOMBS@
436 _GL_FUNCDECL_SYS (wcsrtombs
, size_t,
437 (char *restrict dest
, const wchar_t **restrict srcp
,
439 mbstate_t *restrict ps
)
440 _GL_ARG_NONNULL ((2)));
442 _GL_CXXALIAS_SYS (wcsrtombs
, size_t,
443 (char *restrict dest
, const wchar_t **restrict srcp
,
445 mbstate_t *restrict ps
));
448 _GL_CXXALIASWARN (wcsrtombs
);
450 #elif defined GNULIB_POSIXCHECK
452 # if HAVE_RAW_DECL_WCSRTOMBS
453 _GL_WARN_ON_USE (wcsrtombs
, "wcsrtombs is unportable - "
454 "use gnulib module wcsrtombs for portability");
459 /* Convert a wide string to a string. */
460 #if @GNULIB_WCSNRTOMBS@
461 # if @REPLACE_WCSNRTOMBS@
462 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
464 # define wcsnrtombs rpl_wcsnrtombs
466 _GL_FUNCDECL_RPL (wcsnrtombs
, size_t,
467 (char *restrict dest
,
468 const wchar_t **restrict srcp
, size_t srclen
,
470 mbstate_t *restrict ps
)
471 _GL_ARG_NONNULL ((2)));
472 _GL_CXXALIAS_RPL (wcsnrtombs
, size_t,
473 (char *restrict dest
,
474 const wchar_t **restrict srcp
, size_t srclen
,
476 mbstate_t *restrict ps
));
478 # if !@HAVE_WCSNRTOMBS@ || (defined __cplusplus && defined __sun)
479 _GL_FUNCDECL_SYS (wcsnrtombs
, size_t,
480 (char *restrict dest
,
481 const wchar_t **restrict srcp
, size_t srclen
,
483 mbstate_t *restrict ps
)
484 _GL_ARG_NONNULL ((2)));
486 _GL_CXXALIAS_SYS (wcsnrtombs
, size_t,
487 (char *restrict dest
,
488 const wchar_t **restrict srcp
, size_t srclen
,
490 mbstate_t *restrict ps
));
493 _GL_CXXALIASWARN (wcsnrtombs
);
495 #elif defined GNULIB_POSIXCHECK
497 # if HAVE_RAW_DECL_WCSNRTOMBS
498 _GL_WARN_ON_USE (wcsnrtombs
, "wcsnrtombs is unportable - "
499 "use gnulib module wcsnrtombs for portability");
504 /* Return the number of screen columns needed for WC. */
506 # if @REPLACE_WCWIDTH@
507 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
509 # define wcwidth rpl_wcwidth
511 _GL_FUNCDECL_RPL (wcwidth
, int, (wchar_t) _GL_ATTRIBUTE_PURE
);
512 _GL_CXXALIAS_RPL (wcwidth
, int, (wchar_t));
514 # if !@HAVE_DECL_WCWIDTH@
515 /* wcwidth exists but is not declared. */
516 _GL_FUNCDECL_SYS (wcwidth
, int, (wchar_t) _GL_ATTRIBUTE_PURE
);
518 _GL_CXXALIAS_SYS (wcwidth
, int, (wchar_t));
521 _GL_CXXALIASWARN (wcwidth
);
523 #elif defined GNULIB_POSIXCHECK
525 # if HAVE_RAW_DECL_WCWIDTH
526 _GL_WARN_ON_USE (wcwidth
, "wcwidth is unportable - "
527 "use gnulib module wcwidth for portability");
532 /* Search N wide characters of S for C. */
535 _GL_FUNCDECL_SYS (wmemchr
, wchar_t *, (const wchar_t *s
, wchar_t c
, size_t n
)
538 /* On some systems, this function is defined as an overloaded function:
540 const wchar_t * std::wmemchr (const wchar_t *, wchar_t, size_t);
541 wchar_t * std::wmemchr (wchar_t *, wchar_t, size_t);
543 _GL_CXXALIAS_SYS_CAST2 (wmemchr
,
544 wchar_t *, (const wchar_t *, wchar_t, size_t),
545 const wchar_t *, (const wchar_t *, wchar_t, size_t));
546 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
547 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
548 _GL_CXXALIASWARN1 (wmemchr
, wchar_t *, (wchar_t *s
, wchar_t c
, size_t n
));
549 _GL_CXXALIASWARN1 (wmemchr
, const wchar_t *,
550 (const wchar_t *s
, wchar_t c
, size_t n
));
551 # elif __GLIBC__ >= 2
552 _GL_CXXALIASWARN (wmemchr
);
554 #elif defined GNULIB_POSIXCHECK
556 # if HAVE_RAW_DECL_WMEMCHR
557 _GL_WARN_ON_USE (wmemchr
, "wmemchr is unportable - "
558 "use gnulib module wmemchr for portability");
563 /* Compare N wide characters of S1 and S2. */
566 _GL_FUNCDECL_SYS (wmemcmp
, int,
567 (const wchar_t *s1
, const wchar_t *s2
, size_t n
)
570 _GL_CXXALIAS_SYS (wmemcmp
, int,
571 (const wchar_t *s1
, const wchar_t *s2
, size_t n
));
573 _GL_CXXALIASWARN (wmemcmp
);
575 #elif defined GNULIB_POSIXCHECK
577 # if HAVE_RAW_DECL_WMEMCMP
578 _GL_WARN_ON_USE (wmemcmp
, "wmemcmp is unportable - "
579 "use gnulib module wmemcmp for portability");
584 /* Copy N wide characters of SRC to DEST. */
587 _GL_FUNCDECL_SYS (wmemcpy
, wchar_t *,
588 (wchar_t *restrict dest
,
589 const wchar_t *restrict src
, size_t n
));
591 _GL_CXXALIAS_SYS (wmemcpy
, wchar_t *,
592 (wchar_t *restrict dest
,
593 const wchar_t *restrict src
, size_t n
));
595 _GL_CXXALIASWARN (wmemcpy
);
597 #elif defined GNULIB_POSIXCHECK
599 # if HAVE_RAW_DECL_WMEMCPY
600 _GL_WARN_ON_USE (wmemcpy
, "wmemcpy is unportable - "
601 "use gnulib module wmemcpy for portability");
606 /* Copy N wide characters of SRC to DEST, guaranteeing correct behavior for
607 overlapping memory areas. */
608 #if @GNULIB_WMEMMOVE@
609 # if !@HAVE_WMEMMOVE@
610 _GL_FUNCDECL_SYS (wmemmove
, wchar_t *,
611 (wchar_t *dest
, const wchar_t *src
, size_t n
));
613 _GL_CXXALIAS_SYS (wmemmove
, wchar_t *,
614 (wchar_t *dest
, const wchar_t *src
, size_t n
));
616 _GL_CXXALIASWARN (wmemmove
);
618 #elif defined GNULIB_POSIXCHECK
620 # if HAVE_RAW_DECL_WMEMMOVE
621 _GL_WARN_ON_USE (wmemmove
, "wmemmove is unportable - "
622 "use gnulib module wmemmove for portability");
627 /* Copy N wide characters of SRC to DEST.
628 Return pointer to wide characters after the last written wide character. */
629 #if @GNULIB_WMEMPCPY@
630 # if !@HAVE_WMEMPCPY@
631 _GL_FUNCDECL_SYS (wmempcpy
, wchar_t *,
632 (wchar_t *restrict dest
,
633 const wchar_t *restrict src
, size_t n
));
635 _GL_CXXALIAS_SYS (wmempcpy
, wchar_t *,
636 (wchar_t *restrict dest
,
637 const wchar_t *restrict src
, size_t n
));
639 _GL_CXXALIASWARN (wmempcpy
);
641 #elif defined GNULIB_POSIXCHECK
643 # if HAVE_RAW_DECL_WMEMPCPY
644 _GL_WARN_ON_USE (wmempcpy
, "wmempcpy is unportable - "
645 "use gnulib module wmempcpy for portability");
650 /* Set N wide characters of S to C. */
653 _GL_FUNCDECL_SYS (wmemset
, wchar_t *, (wchar_t *s
, wchar_t c
, size_t n
));
655 _GL_CXXALIAS_SYS (wmemset
, wchar_t *, (wchar_t *s
, wchar_t c
, size_t n
));
657 _GL_CXXALIASWARN (wmemset
);
659 #elif defined GNULIB_POSIXCHECK
661 # if HAVE_RAW_DECL_WMEMSET
662 _GL_WARN_ON_USE (wmemset
, "wmemset is unportable - "
663 "use gnulib module wmemset for portability");
668 /* Return the number of wide characters in S. */
671 _GL_FUNCDECL_SYS (wcslen
, size_t, (const wchar_t *s
) _GL_ATTRIBUTE_PURE
);
673 _GL_CXXALIAS_SYS (wcslen
, size_t, (const wchar_t *s
));
675 _GL_CXXALIASWARN (wcslen
);
677 #elif defined GNULIB_POSIXCHECK
679 # if HAVE_RAW_DECL_WCSLEN
680 _GL_WARN_ON_USE (wcslen
, "wcslen is unportable - "
681 "use gnulib module wcslen for portability");
686 /* Return the number of wide characters in S, but at most MAXLEN. */
689 _GL_FUNCDECL_SYS (wcsnlen
, size_t, (const wchar_t *s
, size_t maxlen
)
692 _GL_CXXALIAS_SYS (wcsnlen
, size_t, (const wchar_t *s
, size_t maxlen
));
693 _GL_CXXALIASWARN (wcsnlen
);
694 #elif defined GNULIB_POSIXCHECK
696 # if HAVE_RAW_DECL_WCSNLEN
697 _GL_WARN_ON_USE (wcsnlen
, "wcsnlen is unportable - "
698 "use gnulib module wcsnlen for portability");
703 /* Copy SRC to DEST. */
706 _GL_FUNCDECL_SYS (wcscpy
, wchar_t *,
707 (wchar_t *restrict dest
, const wchar_t *restrict src
));
709 _GL_CXXALIAS_SYS (wcscpy
, wchar_t *,
710 (wchar_t *restrict dest
, const wchar_t *restrict src
));
712 _GL_CXXALIASWARN (wcscpy
);
714 #elif defined GNULIB_POSIXCHECK
716 # if HAVE_RAW_DECL_WCSCPY
717 _GL_WARN_ON_USE (wcscpy
, "wcscpy is unportable - "
718 "use gnulib module wcscpy for portability");
723 /* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST. */
726 _GL_FUNCDECL_SYS (wcpcpy
, wchar_t *,
727 (wchar_t *restrict dest
, const wchar_t *restrict src
));
729 _GL_CXXALIAS_SYS (wcpcpy
, wchar_t *,
730 (wchar_t *restrict dest
, const wchar_t *restrict src
));
731 _GL_CXXALIASWARN (wcpcpy
);
732 #elif defined GNULIB_POSIXCHECK
734 # if HAVE_RAW_DECL_WCPCPY
735 _GL_WARN_ON_USE (wcpcpy
, "wcpcpy is unportable - "
736 "use gnulib module wcpcpy for portability");
741 /* Copy no more than N wide characters of SRC to DEST. */
744 _GL_FUNCDECL_SYS (wcsncpy
, wchar_t *,
745 (wchar_t *restrict dest
,
746 const wchar_t *restrict src
, size_t n
));
748 _GL_CXXALIAS_SYS (wcsncpy
, wchar_t *,
749 (wchar_t *restrict dest
,
750 const wchar_t *restrict src
, size_t n
));
752 _GL_CXXALIASWARN (wcsncpy
);
754 #elif defined GNULIB_POSIXCHECK
756 # if HAVE_RAW_DECL_WCSNCPY
757 _GL_WARN_ON_USE (wcsncpy
, "wcsncpy is unportable - "
758 "use gnulib module wcsncpy for portability");
763 /* Copy no more than N characters of SRC to DEST, returning the address of
764 the last character written into DEST. */
767 _GL_FUNCDECL_SYS (wcpncpy
, wchar_t *,
768 (wchar_t *restrict dest
,
769 const wchar_t *restrict src
, size_t n
));
771 _GL_CXXALIAS_SYS (wcpncpy
, wchar_t *,
772 (wchar_t *restrict dest
,
773 const wchar_t *restrict src
, size_t n
));
774 _GL_CXXALIASWARN (wcpncpy
);
775 #elif defined GNULIB_POSIXCHECK
777 # if HAVE_RAW_DECL_WCPNCPY
778 _GL_WARN_ON_USE (wcpncpy
, "wcpncpy is unportable - "
779 "use gnulib module wcpncpy for portability");
784 /* Append SRC onto DEST. */
787 _GL_FUNCDECL_SYS (wcscat
, wchar_t *,
788 (wchar_t *restrict dest
, const wchar_t *restrict src
));
790 _GL_CXXALIAS_SYS (wcscat
, wchar_t *,
791 (wchar_t *restrict dest
, const wchar_t *restrict src
));
793 _GL_CXXALIASWARN (wcscat
);
795 #elif defined GNULIB_POSIXCHECK
797 # if HAVE_RAW_DECL_WCSCAT
798 _GL_WARN_ON_USE (wcscat
, "wcscat is unportable - "
799 "use gnulib module wcscat for portability");
804 /* Append no more than N wide characters of SRC onto DEST. */
807 _GL_FUNCDECL_SYS (wcsncat
, wchar_t *,
808 (wchar_t *restrict dest
, const wchar_t *restrict src
,
811 _GL_CXXALIAS_SYS (wcsncat
, wchar_t *,
812 (wchar_t *restrict dest
, const wchar_t *restrict src
,
815 _GL_CXXALIASWARN (wcsncat
);
817 #elif defined GNULIB_POSIXCHECK
819 # if HAVE_RAW_DECL_WCSNCAT
820 _GL_WARN_ON_USE (wcsncat
, "wcsncat is unportable - "
821 "use gnulib module wcsncat for portability");
826 /* Compare S1 and S2. */
829 _GL_FUNCDECL_SYS (wcscmp
, int, (const wchar_t *s1
, const wchar_t *s2
)
832 _GL_CXXALIAS_SYS (wcscmp
, int, (const wchar_t *s1
, const wchar_t *s2
));
834 _GL_CXXALIASWARN (wcscmp
);
836 #elif defined GNULIB_POSIXCHECK
838 # if HAVE_RAW_DECL_WCSCMP
839 _GL_WARN_ON_USE (wcscmp
, "wcscmp is unportable - "
840 "use gnulib module wcscmp for portability");
845 /* Compare no more than N wide characters of S1 and S2. */
848 _GL_FUNCDECL_SYS (wcsncmp
, int,
849 (const wchar_t *s1
, const wchar_t *s2
, size_t n
)
852 _GL_CXXALIAS_SYS (wcsncmp
, int,
853 (const wchar_t *s1
, const wchar_t *s2
, size_t n
));
855 _GL_CXXALIASWARN (wcsncmp
);
857 #elif defined GNULIB_POSIXCHECK
859 # if HAVE_RAW_DECL_WCSNCMP
860 _GL_WARN_ON_USE (wcsncmp
, "wcsncmp is unportable - "
861 "use gnulib module wcsncmp for portability");
866 /* Compare S1 and S2, ignoring case. */
867 #if @GNULIB_WCSCASECMP@
868 # if !@HAVE_WCSCASECMP@
869 _GL_FUNCDECL_SYS (wcscasecmp
, int, (const wchar_t *s1
, const wchar_t *s2
)
872 _GL_CXXALIAS_SYS (wcscasecmp
, int, (const wchar_t *s1
, const wchar_t *s2
));
873 _GL_CXXALIASWARN (wcscasecmp
);
874 #elif defined GNULIB_POSIXCHECK
876 # if HAVE_RAW_DECL_WCSCASECMP
877 _GL_WARN_ON_USE (wcscasecmp
, "wcscasecmp is unportable - "
878 "use gnulib module wcscasecmp for portability");
883 /* Compare no more than N chars of S1 and S2, ignoring case. */
884 #if @GNULIB_WCSNCASECMP@
885 # if !@HAVE_WCSNCASECMP@
886 _GL_FUNCDECL_SYS (wcsncasecmp
, int,
887 (const wchar_t *s1
, const wchar_t *s2
, size_t n
)
890 _GL_CXXALIAS_SYS (wcsncasecmp
, int,
891 (const wchar_t *s1
, const wchar_t *s2
, size_t n
));
892 _GL_CXXALIASWARN (wcsncasecmp
);
893 #elif defined GNULIB_POSIXCHECK
895 # if HAVE_RAW_DECL_WCSNCASECMP
896 _GL_WARN_ON_USE (wcsncasecmp
, "wcsncasecmp is unportable - "
897 "use gnulib module wcsncasecmp for portability");
902 /* Compare S1 and S2, both interpreted as appropriate to the LC_COLLATE
903 category of the current locale. */
906 _GL_FUNCDECL_SYS (wcscoll
, int, (const wchar_t *s1
, const wchar_t *s2
));
908 _GL_CXXALIAS_SYS (wcscoll
, int, (const wchar_t *s1
, const wchar_t *s2
));
910 _GL_CXXALIASWARN (wcscoll
);
912 #elif defined GNULIB_POSIXCHECK
914 # if HAVE_RAW_DECL_WCSCOLL
915 _GL_WARN_ON_USE (wcscoll
, "wcscoll is unportable - "
916 "use gnulib module wcscoll for portability");
921 /* Transform S2 into array pointed to by S1 such that if wcscmp is applied
922 to two transformed strings the result is the as applying 'wcscoll' to the
926 _GL_FUNCDECL_SYS (wcsxfrm
, size_t,
927 (wchar_t *restrict s1
, const wchar_t *restrict s2
, size_t n
));
929 _GL_CXXALIAS_SYS (wcsxfrm
, size_t,
930 (wchar_t *restrict s1
, const wchar_t *restrict s2
, size_t n
));
932 _GL_CXXALIASWARN (wcsxfrm
);
934 #elif defined GNULIB_POSIXCHECK
936 # if HAVE_RAW_DECL_WCSXFRM
937 _GL_WARN_ON_USE (wcsxfrm
, "wcsxfrm is unportable - "
938 "use gnulib module wcsxfrm for portability");
943 /* Duplicate S, returning an identical malloc'd string. */
946 _GL_FUNCDECL_SYS (wcsdup
, wchar_t *, (const wchar_t *s
));
948 _GL_CXXALIAS_SYS (wcsdup
, wchar_t *, (const wchar_t *s
));
949 _GL_CXXALIASWARN (wcsdup
);
950 #elif defined GNULIB_POSIXCHECK
952 # if HAVE_RAW_DECL_WCSDUP
953 _GL_WARN_ON_USE (wcsdup
, "wcsdup is unportable - "
954 "use gnulib module wcsdup for portability");
959 /* Find the first occurrence of WC in WCS. */
962 _GL_FUNCDECL_SYS (wcschr
, wchar_t *, (const wchar_t *wcs
, wchar_t wc
)
965 /* On some systems, this function is defined as an overloaded function:
967 const wchar_t * std::wcschr (const wchar_t *, wchar_t);
968 wchar_t * std::wcschr (wchar_t *, wchar_t);
970 _GL_CXXALIAS_SYS_CAST2 (wcschr
,
971 wchar_t *, (const wchar_t *, wchar_t),
972 const wchar_t *, (const wchar_t *, wchar_t));
973 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
974 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
975 _GL_CXXALIASWARN1 (wcschr
, wchar_t *, (wchar_t *wcs
, wchar_t wc
));
976 _GL_CXXALIASWARN1 (wcschr
, const wchar_t *, (const wchar_t *wcs
, wchar_t wc
));
977 # elif __GLIBC__ >= 2
978 _GL_CXXALIASWARN (wcschr
);
980 #elif defined GNULIB_POSIXCHECK
982 # if HAVE_RAW_DECL_WCSCHR
983 _GL_WARN_ON_USE (wcschr
, "wcschr is unportable - "
984 "use gnulib module wcschr for portability");
989 /* Find the last occurrence of WC in WCS. */
992 _GL_FUNCDECL_SYS (wcsrchr
, wchar_t *, (const wchar_t *wcs
, wchar_t wc
)
995 /* On some systems, this function is defined as an overloaded function:
997 const wchar_t * std::wcsrchr (const wchar_t *, wchar_t);
998 wchar_t * std::wcsrchr (wchar_t *, wchar_t);
1000 _GL_CXXALIAS_SYS_CAST2 (wcsrchr
,
1001 wchar_t *, (const wchar_t *, wchar_t),
1002 const wchar_t *, (const wchar_t *, wchar_t));
1003 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1004 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1005 _GL_CXXALIASWARN1 (wcsrchr
, wchar_t *, (wchar_t *wcs
, wchar_t wc
));
1006 _GL_CXXALIASWARN1 (wcsrchr
, const wchar_t *, (const wchar_t *wcs
, wchar_t wc
));
1007 # elif __GLIBC__ >= 2
1008 _GL_CXXALIASWARN (wcsrchr
);
1010 #elif defined GNULIB_POSIXCHECK
1012 # if HAVE_RAW_DECL_WCSRCHR
1013 _GL_WARN_ON_USE (wcsrchr
, "wcsrchr is unportable - "
1014 "use gnulib module wcsrchr for portability");
1019 /* Return the length of the initial segmet of WCS which consists entirely
1020 of wide characters not in REJECT. */
1021 #if @GNULIB_WCSCSPN@
1022 # if !@HAVE_WCSCSPN@
1023 _GL_FUNCDECL_SYS (wcscspn
, size_t, (const wchar_t *wcs
, const wchar_t *reject
)
1024 _GL_ATTRIBUTE_PURE
);
1026 _GL_CXXALIAS_SYS (wcscspn
, size_t, (const wchar_t *wcs
, const wchar_t *reject
));
1028 _GL_CXXALIASWARN (wcscspn
);
1030 #elif defined GNULIB_POSIXCHECK
1032 # if HAVE_RAW_DECL_WCSCSPN
1033 _GL_WARN_ON_USE (wcscspn
, "wcscspn is unportable - "
1034 "use gnulib module wcscspn for portability");
1039 /* Return the length of the initial segmet of WCS which consists entirely
1040 of wide characters in ACCEPT. */
1043 _GL_FUNCDECL_SYS (wcsspn
, size_t, (const wchar_t *wcs
, const wchar_t *accept
)
1044 _GL_ATTRIBUTE_PURE
);
1046 _GL_CXXALIAS_SYS (wcsspn
, size_t, (const wchar_t *wcs
, const wchar_t *accept
));
1048 _GL_CXXALIASWARN (wcsspn
);
1050 #elif defined GNULIB_POSIXCHECK
1052 # if HAVE_RAW_DECL_WCSSPN
1053 _GL_WARN_ON_USE (wcsspn
, "wcsspn is unportable - "
1054 "use gnulib module wcsspn for portability");
1059 /* Find the first occurrence in WCS of any character in ACCEPT. */
1060 #if @GNULIB_WCSPBRK@
1061 # if !@HAVE_WCSPBRK@
1062 _GL_FUNCDECL_SYS (wcspbrk
, wchar_t *,
1063 (const wchar_t *wcs
, const wchar_t *accept
)
1064 _GL_ATTRIBUTE_PURE
);
1066 /* On some systems, this function is defined as an overloaded function:
1068 const wchar_t * std::wcspbrk (const wchar_t *, const wchar_t *);
1069 wchar_t * std::wcspbrk (wchar_t *, const wchar_t *);
1071 _GL_CXXALIAS_SYS_CAST2 (wcspbrk
,
1072 wchar_t *, (const wchar_t *, const wchar_t *),
1073 const wchar_t *, (const wchar_t *, const wchar_t *));
1074 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1075 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1076 _GL_CXXALIASWARN1 (wcspbrk
, wchar_t *,
1077 (wchar_t *wcs
, const wchar_t *accept
));
1078 _GL_CXXALIASWARN1 (wcspbrk
, const wchar_t *,
1079 (const wchar_t *wcs
, const wchar_t *accept
));
1080 # elif __GLIBC__ >= 2
1081 _GL_CXXALIASWARN (wcspbrk
);
1083 #elif defined GNULIB_POSIXCHECK
1085 # if HAVE_RAW_DECL_WCSPBRK
1086 _GL_WARN_ON_USE (wcspbrk
, "wcspbrk is unportable - "
1087 "use gnulib module wcspbrk for portability");
1092 /* Find the first occurrence of NEEDLE in HAYSTACK. */
1095 _GL_FUNCDECL_SYS (wcsstr
, wchar_t *,
1096 (const wchar_t *restrict haystack
,
1097 const wchar_t *restrict needle
)
1098 _GL_ATTRIBUTE_PURE
);
1100 /* On some systems, this function is defined as an overloaded function:
1102 const wchar_t * std::wcsstr (const wchar_t *, const wchar_t *);
1103 wchar_t * std::wcsstr (wchar_t *, const wchar_t *);
1105 _GL_CXXALIAS_SYS_CAST2 (wcsstr
,
1107 (const wchar_t *restrict
, const wchar_t *restrict
),
1109 (const wchar_t *restrict
, const wchar_t *restrict
));
1110 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1111 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1112 _GL_CXXALIASWARN1 (wcsstr
, wchar_t *,
1113 (wchar_t *restrict haystack
,
1114 const wchar_t *restrict needle
));
1115 _GL_CXXALIASWARN1 (wcsstr
, const wchar_t *,
1116 (const wchar_t *restrict haystack
,
1117 const wchar_t *restrict needle
));
1118 # elif __GLIBC__ >= 2
1119 _GL_CXXALIASWARN (wcsstr
);
1121 #elif defined GNULIB_POSIXCHECK
1123 # if HAVE_RAW_DECL_WCSSTR
1124 _GL_WARN_ON_USE (wcsstr
, "wcsstr is unportable - "
1125 "use gnulib module wcsstr for portability");
1130 /* Divide WCS into tokens separated by characters in DELIM. */
1132 # if @REPLACE_WCSTOK@
1133 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1135 # define wcstok rpl_wcstok
1137 _GL_FUNCDECL_RPL (wcstok
, wchar_t *,
1138 (wchar_t *restrict wcs
, const wchar_t *restrict delim
,
1139 wchar_t **restrict ptr
));
1140 _GL_CXXALIAS_RPL (wcstok
, wchar_t *,
1141 (wchar_t *restrict wcs
, const wchar_t *restrict delim
,
1142 wchar_t **restrict ptr
));
1145 _GL_FUNCDECL_SYS (wcstok
, wchar_t *,
1146 (wchar_t *restrict wcs
, const wchar_t *restrict delim
,
1147 wchar_t **restrict ptr
));
1149 _GL_CXXALIAS_SYS (wcstok
, wchar_t *,
1150 (wchar_t *restrict wcs
, const wchar_t *restrict delim
,
1151 wchar_t **restrict ptr
));
1154 _GL_CXXALIASWARN (wcstok
);
1156 #elif defined GNULIB_POSIXCHECK
1158 # if HAVE_RAW_DECL_WCSTOK
1159 _GL_WARN_ON_USE (wcstok
, "wcstok is unportable - "
1160 "use gnulib module wcstok for portability");
1165 /* Determine number of column positions required for first N wide
1166 characters (or fewer if S ends before this) in S. */
1167 #if @GNULIB_WCSWIDTH@
1168 # if @REPLACE_WCSWIDTH@
1169 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1171 # define wcswidth rpl_wcswidth
1173 _GL_FUNCDECL_RPL (wcswidth
, int, (const wchar_t *s
, size_t n
)
1174 _GL_ATTRIBUTE_PURE
);
1175 _GL_CXXALIAS_RPL (wcswidth
, int, (const wchar_t *s
, size_t n
));
1177 # if !@HAVE_WCSWIDTH@
1178 _GL_FUNCDECL_SYS (wcswidth
, int, (const wchar_t *s
, size_t n
)
1179 _GL_ATTRIBUTE_PURE
);
1181 _GL_CXXALIAS_SYS (wcswidth
, int, (const wchar_t *s
, size_t n
));
1184 _GL_CXXALIASWARN (wcswidth
);
1186 #elif defined GNULIB_POSIXCHECK
1188 # if HAVE_RAW_DECL_WCSWIDTH
1189 _GL_WARN_ON_USE (wcswidth
, "wcswidth is unportable - "
1190 "use gnulib module wcswidth for portability");
1195 /* Convert *TP to a date and time wide string. See
1196 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsftime.html>. */
1197 #if @GNULIB_WCSFTIME@
1198 # if @REPLACE_WCSFTIME@
1199 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1201 # define wcsftime rpl_wcsftime
1203 _GL_FUNCDECL_RPL (wcsftime
, size_t,
1204 (wchar_t *restrict __buf
, size_t __bufsize
,
1205 const wchar_t *restrict __fmt
,
1206 const struct tm
*restrict __tp
)
1207 _GL_ARG_NONNULL ((1, 3, 4)));
1208 _GL_CXXALIAS_RPL (wcsftime
, size_t,
1209 (wchar_t *restrict __buf
, size_t __bufsize
,
1210 const wchar_t *restrict __fmt
,
1211 const struct tm
*restrict __tp
));
1213 # if !@HAVE_WCSFTIME@
1214 _GL_FUNCDECL_SYS (wcsftime
, size_t,
1215 (wchar_t *restrict __buf
, size_t __bufsize
,
1216 const wchar_t *restrict __fmt
,
1217 const struct tm
*restrict __tp
)
1218 _GL_ARG_NONNULL ((1, 3, 4)));
1220 _GL_CXXALIAS_SYS (wcsftime
, size_t,
1221 (wchar_t *restrict __buf
, size_t __bufsize
,
1222 const wchar_t *restrict __fmt
,
1223 const struct tm
*restrict __tp
));
1226 _GL_CXXALIASWARN (wcsftime
);
1228 #elif defined GNULIB_POSIXCHECK
1230 # if HAVE_RAW_DECL_WCSFTIME
1231 _GL_WARN_ON_USE (wcsftime
, "wcsftime is unportable - "
1232 "use gnulib module wcsftime for portability");
1237 #endif /* _@GUARD_PREFIX@_WCHAR_H */
1238 #endif /* _@GUARD_PREFIX@_WCHAR_H */