1 /* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
3 Copyright (C) 2007-2021 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 2, 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 /* In some builds of uClibc, <wchar.h> is nonexistent and wchar_t is defined
70 But avoid namespace pollution on glibc systems. */
71 #if !(defined __GLIBC__ && !defined __UCLIBC__)
75 /* Include the original <wchar.h> if it exists.
76 Some builds of uClibc lack it. */
77 /* The include_next requires a split double-inclusion guard. */
79 # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
82 #undef _GL_ALREADY_INCLUDING_WCHAR_H
84 #ifndef _@GUARD_PREFIX@_WCHAR_H
85 #define _@GUARD_PREFIX@_WCHAR_H
87 /* The __attribute__ feature is available in gcc versions 2.5 and later.
88 The attribute __pure__ was added in gcc 2.96. */
89 #ifndef _GL_ATTRIBUTE_PURE
90 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
91 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
93 # define _GL_ATTRIBUTE_PURE /* empty */
97 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
99 /* The definition of _GL_ARG_NONNULL is copied here. */
101 /* The definition of _GL_WARN_ON_USE is copied here. */
104 /* Define wint_t and WEOF. (Also done in wctype.in.h.) */
105 #if !@HAVE_WINT_T@ && !defined wint_t
111 /* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h> or
112 <stddef.h>. This is too small: ISO C 99 section 7.24.1.(2) says that
113 wint_t must be "unchanged by default argument promotions". Override it. */
114 # if @GNULIB_OVERRIDES_WINT_T@
115 # if !GNULIB_defined_wint_t
116 # if @HAVE_CRTDEFS_H@
117 # include <crtdefs.h>
121 typedef unsigned int rpl_wint_t
;
123 # define wint_t rpl_wint_t
124 # define GNULIB_defined_wint_t 1
128 # define WEOF ((wint_t) -1)
133 /* Override mbstate_t if it is too small.
134 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
135 implementing mbrtowc for encodings like UTF-8.
136 On AIX and MSVC, mbrtowc needs to be overridden, but mbstate_t exists and is
137 large enough and overriding it would cause problems in C++ mode. */
138 #if !(((defined _WIN32 && !defined __CYGWIN__) || @HAVE_MBSINIT@) && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
139 # if !GNULIB_defined_mbstate_t
140 # if !(defined _AIX || defined _MSC_VER)
141 typedef int rpl_mbstate_t
;
143 # define mbstate_t rpl_mbstate_t
145 # define GNULIB_defined_mbstate_t 1
150 /* Convert a single-byte character to a wide character. */
153 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
155 # define btowc rpl_btowc
157 _GL_FUNCDECL_RPL (btowc
, wint_t, (int c
) _GL_ATTRIBUTE_PURE
);
158 _GL_CXXALIAS_RPL (btowc
, wint_t, (int c
));
161 _GL_FUNCDECL_SYS (btowc
, wint_t, (int c
) _GL_ATTRIBUTE_PURE
);
163 /* Need to cast, because on mingw, the return type is 'unsigned short'. */
164 _GL_CXXALIAS_SYS_CAST (btowc
, wint_t, (int c
));
167 _GL_CXXALIASWARN (btowc
);
169 #elif defined GNULIB_POSIXCHECK
171 # if HAVE_RAW_DECL_BTOWC
172 _GL_WARN_ON_USE (btowc
, "btowc is unportable - "
173 "use gnulib module btowc for portability");
178 /* Convert a wide character to a single-byte character. */
181 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
183 # define wctob rpl_wctob
185 _GL_FUNCDECL_RPL (wctob
, int, (wint_t wc
) _GL_ATTRIBUTE_PURE
);
186 _GL_CXXALIAS_RPL (wctob
, int, (wint_t wc
));
188 # if !defined wctob && !@HAVE_DECL_WCTOB@
189 /* wctob is provided by gnulib, or wctob exists but is not declared. */
190 _GL_FUNCDECL_SYS (wctob
, int, (wint_t wc
) _GL_ATTRIBUTE_PURE
);
192 _GL_CXXALIAS_SYS (wctob
, int, (wint_t wc
));
195 _GL_CXXALIASWARN (wctob
);
197 #elif defined GNULIB_POSIXCHECK
199 # if HAVE_RAW_DECL_WCTOB
200 _GL_WARN_ON_USE (wctob
, "wctob is unportable - "
201 "use gnulib module wctob for portability");
206 /* Test whether *PS is in the initial state. */
208 # if @REPLACE_MBSINIT@
209 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
211 # define mbsinit rpl_mbsinit
213 _GL_FUNCDECL_RPL (mbsinit
, int, (const mbstate_t *ps
));
214 _GL_CXXALIAS_RPL (mbsinit
, int, (const mbstate_t *ps
));
217 _GL_FUNCDECL_SYS (mbsinit
, int, (const mbstate_t *ps
));
219 _GL_CXXALIAS_SYS (mbsinit
, int, (const mbstate_t *ps
));
222 _GL_CXXALIASWARN (mbsinit
);
224 #elif defined GNULIB_POSIXCHECK
226 # if HAVE_RAW_DECL_MBSINIT
227 _GL_WARN_ON_USE (mbsinit
, "mbsinit is unportable - "
228 "use gnulib module mbsinit for portability");
233 /* Convert a multibyte character to a wide character. */
235 # if @REPLACE_MBRTOWC@
236 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
238 # define mbrtowc rpl_mbrtowc
240 _GL_FUNCDECL_RPL (mbrtowc
, size_t,
241 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
,
242 mbstate_t *restrict ps
));
243 _GL_CXXALIAS_RPL (mbrtowc
, size_t,
244 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
,
245 mbstate_t *restrict ps
));
248 _GL_FUNCDECL_SYS (mbrtowc
, size_t,
249 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
,
250 mbstate_t *restrict ps
));
252 _GL_CXXALIAS_SYS (mbrtowc
, size_t,
253 (wchar_t *restrict pwc
, const char *restrict s
, size_t n
,
254 mbstate_t *restrict ps
));
257 _GL_CXXALIASWARN (mbrtowc
);
259 #elif defined GNULIB_POSIXCHECK
261 # if HAVE_RAW_DECL_MBRTOWC
262 _GL_WARN_ON_USE (mbrtowc
, "mbrtowc is unportable - "
263 "use gnulib module mbrtowc for portability");
268 /* Recognize a multibyte character. */
270 # if @REPLACE_MBRLEN@
271 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
273 # define mbrlen rpl_mbrlen
275 _GL_FUNCDECL_RPL (mbrlen
, size_t,
276 (const char *restrict s
, size_t n
, mbstate_t *restrict ps
));
277 _GL_CXXALIAS_RPL (mbrlen
, size_t,
278 (const char *restrict s
, size_t n
, mbstate_t *restrict ps
));
281 _GL_FUNCDECL_SYS (mbrlen
, size_t,
282 (const char *restrict s
, size_t n
, mbstate_t *restrict ps
));
284 _GL_CXXALIAS_SYS (mbrlen
, size_t,
285 (const char *restrict s
, size_t n
, mbstate_t *restrict ps
));
288 _GL_CXXALIASWARN (mbrlen
);
290 #elif defined GNULIB_POSIXCHECK
292 # if HAVE_RAW_DECL_MBRLEN
293 _GL_WARN_ON_USE (mbrlen
, "mbrlen is unportable - "
294 "use gnulib module mbrlen for portability");
299 /* Convert a string to a wide string. */
300 #if @GNULIB_MBSRTOWCS@
301 # if @REPLACE_MBSRTOWCS@
302 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
304 # define mbsrtowcs rpl_mbsrtowcs
306 _GL_FUNCDECL_RPL (mbsrtowcs
, size_t,
307 (wchar_t *restrict dest
,
308 const char **restrict srcp
, size_t len
,
309 mbstate_t *restrict ps
)
310 _GL_ARG_NONNULL ((2)));
311 _GL_CXXALIAS_RPL (mbsrtowcs
, size_t,
312 (wchar_t *restrict dest
,
313 const char **restrict srcp
, size_t len
,
314 mbstate_t *restrict ps
));
316 # if !@HAVE_MBSRTOWCS@
317 _GL_FUNCDECL_SYS (mbsrtowcs
, size_t,
318 (wchar_t *restrict dest
,
319 const char **restrict srcp
, size_t len
,
320 mbstate_t *restrict ps
)
321 _GL_ARG_NONNULL ((2)));
323 _GL_CXXALIAS_SYS (mbsrtowcs
, size_t,
324 (wchar_t *restrict dest
,
325 const char **restrict srcp
, size_t len
,
326 mbstate_t *restrict ps
));
329 _GL_CXXALIASWARN (mbsrtowcs
);
331 #elif defined GNULIB_POSIXCHECK
333 # if HAVE_RAW_DECL_MBSRTOWCS
334 _GL_WARN_ON_USE (mbsrtowcs
, "mbsrtowcs is unportable - "
335 "use gnulib module mbsrtowcs for portability");
340 /* Convert a string to a wide string. */
341 #if @GNULIB_MBSNRTOWCS@
342 # if @REPLACE_MBSNRTOWCS@
343 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
345 # define mbsnrtowcs rpl_mbsnrtowcs
347 _GL_FUNCDECL_RPL (mbsnrtowcs
, size_t,
348 (wchar_t *restrict dest
,
349 const char **restrict srcp
, size_t srclen
, size_t len
,
350 mbstate_t *restrict ps
)
351 _GL_ARG_NONNULL ((2)));
352 _GL_CXXALIAS_RPL (mbsnrtowcs
, size_t,
353 (wchar_t *restrict dest
,
354 const char **restrict srcp
, size_t srclen
, size_t len
,
355 mbstate_t *restrict ps
));
357 # if !@HAVE_MBSNRTOWCS@
358 _GL_FUNCDECL_SYS (mbsnrtowcs
, size_t,
359 (wchar_t *restrict dest
,
360 const char **restrict srcp
, size_t srclen
, size_t len
,
361 mbstate_t *restrict ps
)
362 _GL_ARG_NONNULL ((2)));
364 _GL_CXXALIAS_SYS (mbsnrtowcs
, size_t,
365 (wchar_t *restrict dest
,
366 const char **restrict srcp
, size_t srclen
, size_t len
,
367 mbstate_t *restrict ps
));
369 _GL_CXXALIASWARN (mbsnrtowcs
);
370 #elif defined GNULIB_POSIXCHECK
372 # if HAVE_RAW_DECL_MBSNRTOWCS
373 _GL_WARN_ON_USE (mbsnrtowcs
, "mbsnrtowcs is unportable - "
374 "use gnulib module mbsnrtowcs for portability");
379 /* Convert a wide character to a multibyte character. */
381 # if @REPLACE_WCRTOMB@
382 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
384 # define wcrtomb rpl_wcrtomb
386 _GL_FUNCDECL_RPL (wcrtomb
, size_t,
387 (char *restrict s
, wchar_t wc
, mbstate_t *restrict ps
));
388 _GL_CXXALIAS_RPL (wcrtomb
, size_t,
389 (char *restrict s
, wchar_t wc
, mbstate_t *restrict ps
));
392 _GL_FUNCDECL_SYS (wcrtomb
, size_t,
393 (char *restrict s
, wchar_t wc
, mbstate_t *restrict ps
));
395 _GL_CXXALIAS_SYS (wcrtomb
, size_t,
396 (char *restrict s
, wchar_t wc
, mbstate_t *restrict ps
));
399 _GL_CXXALIASWARN (wcrtomb
);
401 #elif defined GNULIB_POSIXCHECK
403 # if HAVE_RAW_DECL_WCRTOMB
404 _GL_WARN_ON_USE (wcrtomb
, "wcrtomb is unportable - "
405 "use gnulib module wcrtomb for portability");
410 /* Convert a wide string to a string. */
411 #if @GNULIB_WCSRTOMBS@
412 # if @REPLACE_WCSRTOMBS@
413 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
415 # define wcsrtombs rpl_wcsrtombs
417 _GL_FUNCDECL_RPL (wcsrtombs
, size_t,
418 (char *restrict dest
, const wchar_t **restrict srcp
,
420 mbstate_t *restrict ps
)
421 _GL_ARG_NONNULL ((2)));
422 _GL_CXXALIAS_RPL (wcsrtombs
, size_t,
423 (char *restrict dest
, const wchar_t **restrict srcp
,
425 mbstate_t *restrict ps
));
427 # if !@HAVE_WCSRTOMBS@
428 _GL_FUNCDECL_SYS (wcsrtombs
, size_t,
429 (char *restrict dest
, const wchar_t **restrict srcp
,
431 mbstate_t *restrict ps
)
432 _GL_ARG_NONNULL ((2)));
434 _GL_CXXALIAS_SYS (wcsrtombs
, size_t,
435 (char *restrict dest
, const wchar_t **restrict srcp
,
437 mbstate_t *restrict ps
));
440 _GL_CXXALIASWARN (wcsrtombs
);
442 #elif defined GNULIB_POSIXCHECK
444 # if HAVE_RAW_DECL_WCSRTOMBS
445 _GL_WARN_ON_USE (wcsrtombs
, "wcsrtombs is unportable - "
446 "use gnulib module wcsrtombs for portability");
451 /* Convert a wide string to a string. */
452 #if @GNULIB_WCSNRTOMBS@
453 # if @REPLACE_WCSNRTOMBS@
454 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
456 # define wcsnrtombs rpl_wcsnrtombs
458 _GL_FUNCDECL_RPL (wcsnrtombs
, size_t,
459 (char *restrict dest
,
460 const wchar_t **restrict srcp
, size_t srclen
,
462 mbstate_t *restrict ps
)
463 _GL_ARG_NONNULL ((2)));
464 _GL_CXXALIAS_RPL (wcsnrtombs
, size_t,
465 (char *restrict dest
,
466 const wchar_t **restrict srcp
, size_t srclen
,
468 mbstate_t *restrict ps
));
470 # if !@HAVE_WCSNRTOMBS@ || (defined __cplusplus && defined __sun)
471 _GL_FUNCDECL_SYS (wcsnrtombs
, size_t,
472 (char *restrict dest
,
473 const wchar_t **restrict srcp
, size_t srclen
,
475 mbstate_t *restrict ps
)
476 _GL_ARG_NONNULL ((2)));
478 _GL_CXXALIAS_SYS (wcsnrtombs
, size_t,
479 (char *restrict dest
,
480 const wchar_t **restrict srcp
, size_t srclen
,
482 mbstate_t *restrict ps
));
485 _GL_CXXALIASWARN (wcsnrtombs
);
487 #elif defined GNULIB_POSIXCHECK
489 # if HAVE_RAW_DECL_WCSNRTOMBS
490 _GL_WARN_ON_USE (wcsnrtombs
, "wcsnrtombs is unportable - "
491 "use gnulib module wcsnrtombs for portability");
496 /* Return the number of screen columns needed for WC. */
498 # if @REPLACE_WCWIDTH@
499 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
501 # define wcwidth rpl_wcwidth
503 _GL_FUNCDECL_RPL (wcwidth
, int, (wchar_t) _GL_ATTRIBUTE_PURE
);
504 _GL_CXXALIAS_RPL (wcwidth
, int, (wchar_t));
506 # if !@HAVE_DECL_WCWIDTH@
507 /* wcwidth exists but is not declared. */
508 _GL_FUNCDECL_SYS (wcwidth
, int, (wchar_t) _GL_ATTRIBUTE_PURE
);
510 _GL_CXXALIAS_SYS (wcwidth
, int, (wchar_t));
513 _GL_CXXALIASWARN (wcwidth
);
515 #elif defined GNULIB_POSIXCHECK
517 # if HAVE_RAW_DECL_WCWIDTH
518 _GL_WARN_ON_USE (wcwidth
, "wcwidth is unportable - "
519 "use gnulib module wcwidth for portability");
524 /* Search N wide characters of S for C. */
527 _GL_FUNCDECL_SYS (wmemchr
, wchar_t *, (const wchar_t *s
, wchar_t c
, size_t n
)
530 /* On some systems, this function is defined as an overloaded function:
532 const wchar_t * std::wmemchr (const wchar_t *, wchar_t, size_t);
533 wchar_t * std::wmemchr (wchar_t *, wchar_t, size_t);
535 _GL_CXXALIAS_SYS_CAST2 (wmemchr
,
536 wchar_t *, (const wchar_t *, wchar_t, size_t),
537 const wchar_t *, (const wchar_t *, wchar_t, size_t));
538 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
539 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
540 _GL_CXXALIASWARN1 (wmemchr
, wchar_t *, (wchar_t *s
, wchar_t c
, size_t n
));
541 _GL_CXXALIASWARN1 (wmemchr
, const wchar_t *,
542 (const wchar_t *s
, wchar_t c
, size_t n
));
543 # elif __GLIBC__ >= 2
544 _GL_CXXALIASWARN (wmemchr
);
546 #elif defined GNULIB_POSIXCHECK
548 # if HAVE_RAW_DECL_WMEMCHR
549 _GL_WARN_ON_USE (wmemchr
, "wmemchr is unportable - "
550 "use gnulib module wmemchr for portability");
555 /* Compare N wide characters of S1 and S2. */
558 _GL_FUNCDECL_SYS (wmemcmp
, int,
559 (const wchar_t *s1
, const wchar_t *s2
, size_t n
)
562 _GL_CXXALIAS_SYS (wmemcmp
, int,
563 (const wchar_t *s1
, const wchar_t *s2
, size_t n
));
565 _GL_CXXALIASWARN (wmemcmp
);
567 #elif defined GNULIB_POSIXCHECK
569 # if HAVE_RAW_DECL_WMEMCMP
570 _GL_WARN_ON_USE (wmemcmp
, "wmemcmp is unportable - "
571 "use gnulib module wmemcmp for portability");
576 /* Copy N wide characters of SRC to DEST. */
579 _GL_FUNCDECL_SYS (wmemcpy
, wchar_t *,
580 (wchar_t *restrict dest
,
581 const wchar_t *restrict src
, size_t n
));
583 _GL_CXXALIAS_SYS (wmemcpy
, wchar_t *,
584 (wchar_t *restrict dest
,
585 const wchar_t *restrict src
, size_t n
));
587 _GL_CXXALIASWARN (wmemcpy
);
589 #elif defined GNULIB_POSIXCHECK
591 # if HAVE_RAW_DECL_WMEMCPY
592 _GL_WARN_ON_USE (wmemcpy
, "wmemcpy is unportable - "
593 "use gnulib module wmemcpy for portability");
598 /* Copy N wide characters of SRC to DEST, guaranteeing correct behavior for
599 overlapping memory areas. */
600 #if @GNULIB_WMEMMOVE@
601 # if !@HAVE_WMEMMOVE@
602 _GL_FUNCDECL_SYS (wmemmove
, wchar_t *,
603 (wchar_t *dest
, const wchar_t *src
, size_t n
));
605 _GL_CXXALIAS_SYS (wmemmove
, wchar_t *,
606 (wchar_t *dest
, const wchar_t *src
, size_t n
));
608 _GL_CXXALIASWARN (wmemmove
);
610 #elif defined GNULIB_POSIXCHECK
612 # if HAVE_RAW_DECL_WMEMMOVE
613 _GL_WARN_ON_USE (wmemmove
, "wmemmove is unportable - "
614 "use gnulib module wmemmove for portability");
619 /* Copy N wide characters of SRC to DEST.
620 Return pointer to wide characters after the last written wide character. */
621 #if @GNULIB_WMEMPCPY@
622 # if !@HAVE_WMEMPCPY@
623 _GL_FUNCDECL_SYS (wmempcpy
, wchar_t *,
624 (wchar_t *restrict dest
,
625 const wchar_t *restrict src
, size_t n
));
627 _GL_CXXALIAS_SYS (wmempcpy
, wchar_t *,
628 (wchar_t *restrict dest
,
629 const wchar_t *restrict src
, size_t n
));
631 _GL_CXXALIASWARN (wmempcpy
);
633 #elif defined GNULIB_POSIXCHECK
635 # if HAVE_RAW_DECL_WMEMPCPY
636 _GL_WARN_ON_USE (wmempcpy
, "wmempcpy is unportable - "
637 "use gnulib module wmempcpy for portability");
642 /* Set N wide characters of S to C. */
645 _GL_FUNCDECL_SYS (wmemset
, wchar_t *, (wchar_t *s
, wchar_t c
, size_t n
));
647 _GL_CXXALIAS_SYS (wmemset
, wchar_t *, (wchar_t *s
, wchar_t c
, size_t n
));
649 _GL_CXXALIASWARN (wmemset
);
651 #elif defined GNULIB_POSIXCHECK
653 # if HAVE_RAW_DECL_WMEMSET
654 _GL_WARN_ON_USE (wmemset
, "wmemset is unportable - "
655 "use gnulib module wmemset for portability");
660 /* Return the number of wide characters in S. */
663 _GL_FUNCDECL_SYS (wcslen
, size_t, (const wchar_t *s
) _GL_ATTRIBUTE_PURE
);
665 _GL_CXXALIAS_SYS (wcslen
, size_t, (const wchar_t *s
));
667 _GL_CXXALIASWARN (wcslen
);
669 #elif defined GNULIB_POSIXCHECK
671 # if HAVE_RAW_DECL_WCSLEN
672 _GL_WARN_ON_USE (wcslen
, "wcslen is unportable - "
673 "use gnulib module wcslen for portability");
678 /* Return the number of wide characters in S, but at most MAXLEN. */
681 _GL_FUNCDECL_SYS (wcsnlen
, size_t, (const wchar_t *s
, size_t maxlen
)
684 _GL_CXXALIAS_SYS (wcsnlen
, size_t, (const wchar_t *s
, size_t maxlen
));
685 _GL_CXXALIASWARN (wcsnlen
);
686 #elif defined GNULIB_POSIXCHECK
688 # if HAVE_RAW_DECL_WCSNLEN
689 _GL_WARN_ON_USE (wcsnlen
, "wcsnlen is unportable - "
690 "use gnulib module wcsnlen for portability");
695 /* Copy SRC to DEST. */
698 _GL_FUNCDECL_SYS (wcscpy
, wchar_t *,
699 (wchar_t *restrict dest
, const wchar_t *restrict src
));
701 _GL_CXXALIAS_SYS (wcscpy
, wchar_t *,
702 (wchar_t *restrict dest
, const wchar_t *restrict src
));
704 _GL_CXXALIASWARN (wcscpy
);
706 #elif defined GNULIB_POSIXCHECK
708 # if HAVE_RAW_DECL_WCSCPY
709 _GL_WARN_ON_USE (wcscpy
, "wcscpy is unportable - "
710 "use gnulib module wcscpy for portability");
715 /* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST. */
718 _GL_FUNCDECL_SYS (wcpcpy
, wchar_t *,
719 (wchar_t *restrict dest
, const wchar_t *restrict src
));
721 _GL_CXXALIAS_SYS (wcpcpy
, wchar_t *,
722 (wchar_t *restrict dest
, const wchar_t *restrict src
));
723 _GL_CXXALIASWARN (wcpcpy
);
724 #elif defined GNULIB_POSIXCHECK
726 # if HAVE_RAW_DECL_WCPCPY
727 _GL_WARN_ON_USE (wcpcpy
, "wcpcpy is unportable - "
728 "use gnulib module wcpcpy for portability");
733 /* Copy no more than N wide characters of SRC to DEST. */
736 _GL_FUNCDECL_SYS (wcsncpy
, wchar_t *,
737 (wchar_t *restrict dest
,
738 const wchar_t *restrict src
, size_t n
));
740 _GL_CXXALIAS_SYS (wcsncpy
, wchar_t *,
741 (wchar_t *restrict dest
,
742 const wchar_t *restrict src
, size_t n
));
744 _GL_CXXALIASWARN (wcsncpy
);
746 #elif defined GNULIB_POSIXCHECK
748 # if HAVE_RAW_DECL_WCSNCPY
749 _GL_WARN_ON_USE (wcsncpy
, "wcsncpy is unportable - "
750 "use gnulib module wcsncpy for portability");
755 /* Copy no more than N characters of SRC to DEST, returning the address of
756 the last character written into DEST. */
759 _GL_FUNCDECL_SYS (wcpncpy
, wchar_t *,
760 (wchar_t *restrict dest
,
761 const wchar_t *restrict src
, size_t n
));
763 _GL_CXXALIAS_SYS (wcpncpy
, wchar_t *,
764 (wchar_t *restrict dest
,
765 const wchar_t *restrict src
, size_t n
));
766 _GL_CXXALIASWARN (wcpncpy
);
767 #elif defined GNULIB_POSIXCHECK
769 # if HAVE_RAW_DECL_WCPNCPY
770 _GL_WARN_ON_USE (wcpncpy
, "wcpncpy is unportable - "
771 "use gnulib module wcpncpy for portability");
776 /* Append SRC onto DEST. */
779 _GL_FUNCDECL_SYS (wcscat
, wchar_t *,
780 (wchar_t *restrict dest
, const wchar_t *restrict src
));
782 _GL_CXXALIAS_SYS (wcscat
, wchar_t *,
783 (wchar_t *restrict dest
, const wchar_t *restrict src
));
785 _GL_CXXALIASWARN (wcscat
);
787 #elif defined GNULIB_POSIXCHECK
789 # if HAVE_RAW_DECL_WCSCAT
790 _GL_WARN_ON_USE (wcscat
, "wcscat is unportable - "
791 "use gnulib module wcscat for portability");
796 /* Append no more than N wide characters of SRC onto DEST. */
799 _GL_FUNCDECL_SYS (wcsncat
, wchar_t *,
800 (wchar_t *restrict dest
, const wchar_t *restrict src
,
803 _GL_CXXALIAS_SYS (wcsncat
, wchar_t *,
804 (wchar_t *restrict dest
, const wchar_t *restrict src
,
807 _GL_CXXALIASWARN (wcsncat
);
809 #elif defined GNULIB_POSIXCHECK
811 # if HAVE_RAW_DECL_WCSNCAT
812 _GL_WARN_ON_USE (wcsncat
, "wcsncat is unportable - "
813 "use gnulib module wcsncat for portability");
818 /* Compare S1 and S2. */
821 _GL_FUNCDECL_SYS (wcscmp
, int, (const wchar_t *s1
, const wchar_t *s2
)
824 _GL_CXXALIAS_SYS (wcscmp
, int, (const wchar_t *s1
, const wchar_t *s2
));
826 _GL_CXXALIASWARN (wcscmp
);
828 #elif defined GNULIB_POSIXCHECK
830 # if HAVE_RAW_DECL_WCSCMP
831 _GL_WARN_ON_USE (wcscmp
, "wcscmp is unportable - "
832 "use gnulib module wcscmp for portability");
837 /* Compare no more than N wide characters of S1 and S2. */
840 _GL_FUNCDECL_SYS (wcsncmp
, int,
841 (const wchar_t *s1
, const wchar_t *s2
, size_t n
)
844 _GL_CXXALIAS_SYS (wcsncmp
, int,
845 (const wchar_t *s1
, const wchar_t *s2
, size_t n
));
847 _GL_CXXALIASWARN (wcsncmp
);
849 #elif defined GNULIB_POSIXCHECK
851 # if HAVE_RAW_DECL_WCSNCMP
852 _GL_WARN_ON_USE (wcsncmp
, "wcsncmp is unportable - "
853 "use gnulib module wcsncmp for portability");
858 /* Compare S1 and S2, ignoring case. */
859 #if @GNULIB_WCSCASECMP@
860 # if !@HAVE_WCSCASECMP@
861 _GL_FUNCDECL_SYS (wcscasecmp
, int, (const wchar_t *s1
, const wchar_t *s2
)
864 _GL_CXXALIAS_SYS (wcscasecmp
, int, (const wchar_t *s1
, const wchar_t *s2
));
865 _GL_CXXALIASWARN (wcscasecmp
);
866 #elif defined GNULIB_POSIXCHECK
868 # if HAVE_RAW_DECL_WCSCASECMP
869 _GL_WARN_ON_USE (wcscasecmp
, "wcscasecmp is unportable - "
870 "use gnulib module wcscasecmp for portability");
875 /* Compare no more than N chars of S1 and S2, ignoring case. */
876 #if @GNULIB_WCSNCASECMP@
877 # if !@HAVE_WCSNCASECMP@
878 _GL_FUNCDECL_SYS (wcsncasecmp
, int,
879 (const wchar_t *s1
, const wchar_t *s2
, size_t n
)
882 _GL_CXXALIAS_SYS (wcsncasecmp
, int,
883 (const wchar_t *s1
, const wchar_t *s2
, size_t n
));
884 _GL_CXXALIASWARN (wcsncasecmp
);
885 #elif defined GNULIB_POSIXCHECK
887 # if HAVE_RAW_DECL_WCSNCASECMP
888 _GL_WARN_ON_USE (wcsncasecmp
, "wcsncasecmp is unportable - "
889 "use gnulib module wcsncasecmp for portability");
894 /* Compare S1 and S2, both interpreted as appropriate to the LC_COLLATE
895 category of the current locale. */
898 _GL_FUNCDECL_SYS (wcscoll
, int, (const wchar_t *s1
, const wchar_t *s2
));
900 _GL_CXXALIAS_SYS (wcscoll
, int, (const wchar_t *s1
, const wchar_t *s2
));
902 _GL_CXXALIASWARN (wcscoll
);
904 #elif defined GNULIB_POSIXCHECK
906 # if HAVE_RAW_DECL_WCSCOLL
907 _GL_WARN_ON_USE (wcscoll
, "wcscoll is unportable - "
908 "use gnulib module wcscoll for portability");
913 /* Transform S2 into array pointed to by S1 such that if wcscmp is applied
914 to two transformed strings the result is the as applying 'wcscoll' to the
918 _GL_FUNCDECL_SYS (wcsxfrm
, size_t,
919 (wchar_t *restrict s1
, const wchar_t *restrict s2
, size_t n
));
921 _GL_CXXALIAS_SYS (wcsxfrm
, size_t,
922 (wchar_t *restrict s1
, const wchar_t *restrict s2
, size_t n
));
924 _GL_CXXALIASWARN (wcsxfrm
);
926 #elif defined GNULIB_POSIXCHECK
928 # if HAVE_RAW_DECL_WCSXFRM
929 _GL_WARN_ON_USE (wcsxfrm
, "wcsxfrm is unportable - "
930 "use gnulib module wcsxfrm for portability");
935 /* Duplicate S, returning an identical malloc'd string. */
937 # if defined _WIN32 && !defined __CYGWIN__
938 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
940 # define wcsdup _wcsdup
942 _GL_CXXALIAS_MDA (wcsdup
, wchar_t *, (const wchar_t *s
));
945 _GL_FUNCDECL_SYS (wcsdup
, wchar_t *, (const wchar_t *s
));
947 _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");
956 #elif @GNULIB_MDA_WCSDUP@
957 /* On native Windows, map 'wcsdup' to '_wcsdup', so that -loldnames is not
958 required. In C++ with GNULIB_NAMESPACE, avoid differences between
959 platforms by defining GNULIB_NAMESPACE::wcsdup always. */
960 # if defined _WIN32 && !defined __CYGWIN__
961 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
963 # define wcsdup _wcsdup
965 _GL_CXXALIAS_MDA (wcsdup
, wchar_t *, (const wchar_t *s
));
967 _GL_FUNCDECL_SYS (wcsdup
, wchar_t *, (const wchar_t *s
));
968 # if @HAVE_DECL_WCSDUP@
969 _GL_CXXALIAS_SYS (wcsdup
, wchar_t *, (const wchar_t *s
));
972 # if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_WCSDUP@
973 _GL_CXXALIASWARN (wcsdup
);
978 /* Find the first occurrence of WC in WCS. */
981 _GL_FUNCDECL_SYS (wcschr
, wchar_t *, (const wchar_t *wcs
, wchar_t wc
)
984 /* On some systems, this function is defined as an overloaded function:
986 const wchar_t * std::wcschr (const wchar_t *, wchar_t);
987 wchar_t * std::wcschr (wchar_t *, wchar_t);
989 _GL_CXXALIAS_SYS_CAST2 (wcschr
,
990 wchar_t *, (const wchar_t *, wchar_t),
991 const wchar_t *, (const wchar_t *, wchar_t));
992 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
993 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
994 _GL_CXXALIASWARN1 (wcschr
, wchar_t *, (wchar_t *wcs
, wchar_t wc
));
995 _GL_CXXALIASWARN1 (wcschr
, const wchar_t *, (const wchar_t *wcs
, wchar_t wc
));
996 # elif __GLIBC__ >= 2
997 _GL_CXXALIASWARN (wcschr
);
999 #elif defined GNULIB_POSIXCHECK
1001 # if HAVE_RAW_DECL_WCSCHR
1002 _GL_WARN_ON_USE (wcschr
, "wcschr is unportable - "
1003 "use gnulib module wcschr for portability");
1008 /* Find the last occurrence of WC in WCS. */
1009 #if @GNULIB_WCSRCHR@
1010 # if !@HAVE_WCSRCHR@
1011 _GL_FUNCDECL_SYS (wcsrchr
, wchar_t *, (const wchar_t *wcs
, wchar_t wc
)
1012 _GL_ATTRIBUTE_PURE
);
1014 /* On some systems, this function is defined as an overloaded function:
1016 const wchar_t * std::wcsrchr (const wchar_t *, wchar_t);
1017 wchar_t * std::wcsrchr (wchar_t *, wchar_t);
1019 _GL_CXXALIAS_SYS_CAST2 (wcsrchr
,
1020 wchar_t *, (const wchar_t *, wchar_t),
1021 const wchar_t *, (const wchar_t *, wchar_t));
1022 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1023 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1024 _GL_CXXALIASWARN1 (wcsrchr
, wchar_t *, (wchar_t *wcs
, wchar_t wc
));
1025 _GL_CXXALIASWARN1 (wcsrchr
, const wchar_t *, (const wchar_t *wcs
, wchar_t wc
));
1026 # elif __GLIBC__ >= 2
1027 _GL_CXXALIASWARN (wcsrchr
);
1029 #elif defined GNULIB_POSIXCHECK
1031 # if HAVE_RAW_DECL_WCSRCHR
1032 _GL_WARN_ON_USE (wcsrchr
, "wcsrchr is unportable - "
1033 "use gnulib module wcsrchr for portability");
1038 /* Return the length of the initial segmet of WCS which consists entirely
1039 of wide characters not in REJECT. */
1040 #if @GNULIB_WCSCSPN@
1041 # if !@HAVE_WCSCSPN@
1042 _GL_FUNCDECL_SYS (wcscspn
, size_t, (const wchar_t *wcs
, const wchar_t *reject
)
1043 _GL_ATTRIBUTE_PURE
);
1045 _GL_CXXALIAS_SYS (wcscspn
, size_t, (const wchar_t *wcs
, const wchar_t *reject
));
1047 _GL_CXXALIASWARN (wcscspn
);
1049 #elif defined GNULIB_POSIXCHECK
1051 # if HAVE_RAW_DECL_WCSCSPN
1052 _GL_WARN_ON_USE (wcscspn
, "wcscspn is unportable - "
1053 "use gnulib module wcscspn for portability");
1058 /* Return the length of the initial segmet of WCS which consists entirely
1059 of wide characters in ACCEPT. */
1062 _GL_FUNCDECL_SYS (wcsspn
, size_t, (const wchar_t *wcs
, const wchar_t *accept
)
1063 _GL_ATTRIBUTE_PURE
);
1065 _GL_CXXALIAS_SYS (wcsspn
, size_t, (const wchar_t *wcs
, const wchar_t *accept
));
1067 _GL_CXXALIASWARN (wcsspn
);
1069 #elif defined GNULIB_POSIXCHECK
1071 # if HAVE_RAW_DECL_WCSSPN
1072 _GL_WARN_ON_USE (wcsspn
, "wcsspn is unportable - "
1073 "use gnulib module wcsspn for portability");
1078 /* Find the first occurrence in WCS of any character in ACCEPT. */
1079 #if @GNULIB_WCSPBRK@
1080 # if !@HAVE_WCSPBRK@
1081 _GL_FUNCDECL_SYS (wcspbrk
, wchar_t *,
1082 (const wchar_t *wcs
, const wchar_t *accept
)
1083 _GL_ATTRIBUTE_PURE
);
1085 /* On some systems, this function is defined as an overloaded function:
1087 const wchar_t * std::wcspbrk (const wchar_t *, const wchar_t *);
1088 wchar_t * std::wcspbrk (wchar_t *, const wchar_t *);
1090 _GL_CXXALIAS_SYS_CAST2 (wcspbrk
,
1091 wchar_t *, (const wchar_t *, const wchar_t *),
1092 const wchar_t *, (const wchar_t *, const wchar_t *));
1093 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1094 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1095 _GL_CXXALIASWARN1 (wcspbrk
, wchar_t *,
1096 (wchar_t *wcs
, const wchar_t *accept
));
1097 _GL_CXXALIASWARN1 (wcspbrk
, const wchar_t *,
1098 (const wchar_t *wcs
, const wchar_t *accept
));
1099 # elif __GLIBC__ >= 2
1100 _GL_CXXALIASWARN (wcspbrk
);
1102 #elif defined GNULIB_POSIXCHECK
1104 # if HAVE_RAW_DECL_WCSPBRK
1105 _GL_WARN_ON_USE (wcspbrk
, "wcspbrk is unportable - "
1106 "use gnulib module wcspbrk for portability");
1111 /* Find the first occurrence of NEEDLE in HAYSTACK. */
1114 _GL_FUNCDECL_SYS (wcsstr
, wchar_t *,
1115 (const wchar_t *restrict haystack
,
1116 const wchar_t *restrict needle
)
1117 _GL_ATTRIBUTE_PURE
);
1119 /* On some systems, this function is defined as an overloaded function:
1121 const wchar_t * std::wcsstr (const wchar_t *, const wchar_t *);
1122 wchar_t * std::wcsstr (wchar_t *, const wchar_t *);
1124 _GL_CXXALIAS_SYS_CAST2 (wcsstr
,
1126 (const wchar_t *restrict
, const wchar_t *restrict
),
1128 (const wchar_t *restrict
, const wchar_t *restrict
));
1129 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1130 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1131 _GL_CXXALIASWARN1 (wcsstr
, wchar_t *,
1132 (wchar_t *restrict haystack
,
1133 const wchar_t *restrict needle
));
1134 _GL_CXXALIASWARN1 (wcsstr
, const wchar_t *,
1135 (const wchar_t *restrict haystack
,
1136 const wchar_t *restrict needle
));
1137 # elif __GLIBC__ >= 2
1138 _GL_CXXALIASWARN (wcsstr
);
1140 #elif defined GNULIB_POSIXCHECK
1142 # if HAVE_RAW_DECL_WCSSTR
1143 _GL_WARN_ON_USE (wcsstr
, "wcsstr is unportable - "
1144 "use gnulib module wcsstr for portability");
1149 /* Divide WCS into tokens separated by characters in DELIM. */
1151 # if @REPLACE_WCSTOK@
1152 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1154 # define wcstok rpl_wcstok
1156 _GL_FUNCDECL_RPL (wcstok
, wchar_t *,
1157 (wchar_t *restrict wcs
, const wchar_t *restrict delim
,
1158 wchar_t **restrict ptr
));
1159 _GL_CXXALIAS_RPL (wcstok
, wchar_t *,
1160 (wchar_t *restrict wcs
, const wchar_t *restrict delim
,
1161 wchar_t **restrict ptr
));
1164 _GL_FUNCDECL_SYS (wcstok
, wchar_t *,
1165 (wchar_t *restrict wcs
, const wchar_t *restrict delim
,
1166 wchar_t **restrict ptr
));
1168 _GL_CXXALIAS_SYS (wcstok
, wchar_t *,
1169 (wchar_t *restrict wcs
, const wchar_t *restrict delim
,
1170 wchar_t **restrict ptr
));
1173 _GL_CXXALIASWARN (wcstok
);
1175 #elif defined GNULIB_POSIXCHECK
1177 # if HAVE_RAW_DECL_WCSTOK
1178 _GL_WARN_ON_USE (wcstok
, "wcstok is unportable - "
1179 "use gnulib module wcstok for portability");
1184 /* Determine number of column positions required for first N wide
1185 characters (or fewer if S ends before this) in S. */
1186 #if @GNULIB_WCSWIDTH@
1187 # if @REPLACE_WCSWIDTH@
1188 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1190 # define wcswidth rpl_wcswidth
1192 _GL_FUNCDECL_RPL (wcswidth
, int, (const wchar_t *s
, size_t n
)
1193 _GL_ATTRIBUTE_PURE
);
1194 _GL_CXXALIAS_RPL (wcswidth
, int, (const wchar_t *s
, size_t n
));
1196 # if !@HAVE_WCSWIDTH@
1197 _GL_FUNCDECL_SYS (wcswidth
, int, (const wchar_t *s
, size_t n
)
1198 _GL_ATTRIBUTE_PURE
);
1200 _GL_CXXALIAS_SYS (wcswidth
, int, (const wchar_t *s
, size_t n
));
1203 _GL_CXXALIASWARN (wcswidth
);
1205 #elif defined GNULIB_POSIXCHECK
1207 # if HAVE_RAW_DECL_WCSWIDTH
1208 _GL_WARN_ON_USE (wcswidth
, "wcswidth is unportable - "
1209 "use gnulib module wcswidth for portability");
1214 /* Convert *TP to a date and time wide string. See
1215 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsftime.html>. */
1216 #if @GNULIB_WCSFTIME@
1217 # if @REPLACE_WCSFTIME@
1218 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1220 # define wcsftime rpl_wcsftime
1222 _GL_FUNCDECL_RPL (wcsftime
, size_t,
1223 (wchar_t *restrict __buf
, size_t __bufsize
,
1224 const wchar_t *restrict __fmt
,
1225 const struct tm
*restrict __tp
)
1226 _GL_ARG_NONNULL ((1, 3, 4)));
1227 _GL_CXXALIAS_RPL (wcsftime
, size_t,
1228 (wchar_t *restrict __buf
, size_t __bufsize
,
1229 const wchar_t *restrict __fmt
,
1230 const struct tm
*restrict __tp
));
1232 # if !@HAVE_WCSFTIME@
1233 _GL_FUNCDECL_SYS (wcsftime
, size_t,
1234 (wchar_t *restrict __buf
, size_t __bufsize
,
1235 const wchar_t *restrict __fmt
,
1236 const struct tm
*restrict __tp
)
1237 _GL_ARG_NONNULL ((1, 3, 4)));
1239 _GL_CXXALIAS_SYS (wcsftime
, size_t,
1240 (wchar_t *restrict __buf
, size_t __bufsize
,
1241 const wchar_t *restrict __fmt
,
1242 const struct tm
*restrict __tp
));
1245 _GL_CXXALIASWARN (wcsftime
);
1247 #elif defined GNULIB_POSIXCHECK
1249 # if HAVE_RAW_DECL_WCSFTIME
1250 _GL_WARN_ON_USE (wcsftime
, "wcsftime is unportable - "
1251 "use gnulib module wcsftime for portability");
1256 #endif /* _@GUARD_PREFIX@_WCHAR_H */
1257 #endif /* _@GUARD_PREFIX@_WCHAR_H */