1/* Copyright (C) 1995-2026 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library 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 GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18/*
19 * ISO C99 Standard: 7.24
20 * Extended multibyte and wide character utilities <wchar.h>
21 */
22
23#ifndef _WCHAR_H
24#define _WCHAR_H 1
25
26#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
27#include <bits/libc-header-start.h>
28
29/* Gather machine dependent type support. */
30#include <bits/floatn.h>
31
32#define __need_size_t
33#define __need_wchar_t
34#define __need_NULL
35#include <stddef.h>
36
37#define __need___va_list
38#include <stdarg.h>
39
40#if defined __USE_XOPEN2K || defined __USE_XOPEN2K8
41# ifdef __GNUC__
42# ifndef _VA_LIST_DEFINED
43typedef __gnuc_va_list va_list;
44# define _VA_LIST_DEFINED
45# endif
46# else
47# include <stdarg.h>
48# endif
49#endif
50
51#include <bits/wchar.h>
52#include <bits/types/wint_t.h>
53#include <bits/types/mbstate_t.h>
54#include <bits/types/__FILE.h>
55
56#if defined __USE_UNIX98 || defined __USE_XOPEN2K
57# include <bits/types/FILE.h>
58#endif
59#ifdef __USE_XOPEN2K8
60# include <bits/types/locale_t.h>
61#endif
62
63#if __GLIBC_USE (ISOC23)
64# define __STDC_VERSION_WCHAR_H__ 202311L
65#endif
66
67/* Tell the caller that we provide correct C++ prototypes. */
68#if defined __cplusplus && __GNUC_PREREQ (4, 4)
69# define __CORRECT_ISO_CPP_WCHAR_H_PROTO
70#endif
71
72#ifndef WCHAR_MIN
73/* These constants might also be defined in <inttypes.h>. */
74# define WCHAR_MIN __WCHAR_MIN
75# define WCHAR_MAX __WCHAR_MAX
76#endif
77
78#ifndef WEOF
79# define WEOF (0xffffffffu)
80#endif
81
82/* All versions of XPG prior to the publication of ISO C99 required
83 the bulk of <wctype.h>'s declarations to appear in this header
84 (because <wctype.h> did not exist prior to C99). In POSIX.1-2001
85 those declarations were marked as XSI extensions; in -2008 they
86 were additionally marked as obsolescent. _GNU_SOURCE mode
87 anticipates the removal of these declarations in the next revision
88 of POSIX. */
89#if (defined __USE_XOPEN && !defined __USE_GNU \
90 && !(defined __USE_XOPEN2K && !defined __USE_XOPEN2KXSI))
91# include <bits/wctype-wchar.h>
92#endif
93
94__BEGIN_DECLS
95
96/* This incomplete type is defined in <time.h> but needed here because
97 of `wcsftime'. */
98struct tm;
99
100
101/* Copy SRC to DEST. */
102extern wchar_t *wcscpy (wchar_t *__restrict __dest,
103 const wchar_t *__restrict __src)
104 __THROW __nonnull ((1, 2));
105
106/* Copy no more than N wide-characters of SRC to DEST. */
107extern wchar_t *wcsncpy (wchar_t *__restrict __dest,
108 const wchar_t *__restrict __src, size_t __n)
109 __THROW __nonnull ((1, 2));
110
111#ifdef __USE_MISC
112/* Copy at most N - 1 characters from SRC to DEST. */
113extern size_t wcslcpy (wchar_t *__restrict __dest,
114 const wchar_t *__restrict __src, size_t __n)
115 __THROW __nonnull ((1, 2)) __attr_access ((__write_only__, 1, 3));
116
117/* Append SRC to DEST, possibly with truncation to keep the total size
118 below N. */
119extern size_t wcslcat (wchar_t *__restrict __dest,
120 const wchar_t *__restrict __src, size_t __n)
121 __THROW __nonnull ((1, 2)) __attr_access ((__read_write__, 1, 3));
122#endif
123
124/* Append SRC onto DEST. */
125extern wchar_t *wcscat (wchar_t *__restrict __dest,
126 const wchar_t *__restrict __src)
127 __THROW __nonnull ((1, 2));
128/* Append no more than N wide-characters of SRC onto DEST. */
129extern wchar_t *wcsncat (wchar_t *__restrict __dest,
130 const wchar_t *__restrict __src, size_t __n)
131 __THROW __nonnull ((1, 2));
132
133/* Compare S1 and S2. */
134extern int wcscmp (const wchar_t *__s1, const wchar_t *__s2)
135 __THROW __attribute_pure__ __nonnull ((1, 2));
136/* Compare N wide-characters of S1 and S2. */
137extern int wcsncmp (const wchar_t *__s1, const wchar_t *__s2, size_t __n)
138 __THROW __attribute_pure__ __nonnull ((1, 2));
139
140#ifdef __USE_XOPEN2K8
141/* Compare S1 and S2, ignoring case. */
142extern int wcscasecmp (const wchar_t *__s1, const wchar_t *__s2) __THROW;
143
144/* Compare no more than N chars of S1 and S2, ignoring case. */
145extern int wcsncasecmp (const wchar_t *__s1, const wchar_t *__s2,
146 size_t __n) __THROW;
147
148/* Similar to the two functions above but take the information from
149 the provided locale and not the global locale. */
150extern int wcscasecmp_l (const wchar_t *__s1, const wchar_t *__s2,
151 locale_t __loc) __THROW;
152
153extern int wcsncasecmp_l (const wchar_t *__s1, const wchar_t *__s2,
154 size_t __n, locale_t __loc) __THROW;
155#endif
156
157/* Compare S1 and S2, both interpreted as appropriate to the
158 LC_COLLATE category of the current locale. */
159extern int wcscoll (const wchar_t *__s1, const wchar_t *__s2) __THROW;
160/* Transform S2 into array pointed to by S1 such that if wcscmp is
161 applied to two transformed strings the result is the as applying
162 `wcscoll' to the original strings. */
163extern size_t wcsxfrm (wchar_t *__restrict __s1,
164 const wchar_t *__restrict __s2, size_t __n) __THROW;
165
166#ifdef __USE_XOPEN2K8
167/* Similar to the two functions above but take the information from
168 the provided locale and not the global locale. */
169
170/* Compare S1 and S2, both interpreted as appropriate to the
171 LC_COLLATE category of the given locale. */
172extern int wcscoll_l (const wchar_t *__s1, const wchar_t *__s2,
173 locale_t __loc) __THROW;
174
175/* Transform S2 into array pointed to by S1 such that if wcscmp is
176 applied to two transformed strings the result is the as applying
177 `wcscoll' to the original strings. */
178extern size_t wcsxfrm_l (wchar_t *__s1, const wchar_t *__s2,
179 size_t __n, locale_t __loc) __THROW;
180
181/* Duplicate S, returning an identical malloc'd string. */
182extern wchar_t *wcsdup (const wchar_t *__s) __THROW
183 __attribute_malloc__ __attr_dealloc_free;
184#endif
185
186/* Find the first occurrence of WC in WCS. */
187#ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
188extern "C++" wchar_t *wcschr (wchar_t *__wcs, wchar_t __wc)
189 __THROW __asm ("wcschr") __attribute_pure__;
190extern "C++" const wchar_t *wcschr (const wchar_t *__wcs, wchar_t __wc)
191 __THROW __asm ("wcschr") __attribute_pure__;
192#else
193extern wchar_t *wcschr (const wchar_t *__wcs, wchar_t __wc)
194 __THROW __attribute_pure__;
195# if __GLIBC_USE (ISOC23) && defined __glibc_const_generic && !defined _LIBC
196# define wcschr(WCS, WC) \
197 __glibc_const_generic (WCS, const wchar_t *, wcschr (WCS, WC))
198# endif
199#endif
200/* Find the last occurrence of WC in WCS. */
201#ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
202extern "C++" wchar_t *wcsrchr (wchar_t *__wcs, wchar_t __wc)
203 __THROW __asm ("wcsrchr") __attribute_pure__;
204extern "C++" const wchar_t *wcsrchr (const wchar_t *__wcs, wchar_t __wc)
205 __THROW __asm ("wcsrchr") __attribute_pure__;
206#else
207extern wchar_t *wcsrchr (const wchar_t *__wcs, wchar_t __wc)
208 __THROW __attribute_pure__;
209# if __GLIBC_USE (ISOC23) && defined __glibc_const_generic && !defined _LIBC
210# define wcsrchr(WCS, WC) \
211 __glibc_const_generic (WCS, const wchar_t *, wcsrchr (WCS, WC))
212# endif
213#endif
214
215#ifdef __USE_GNU
216/* This function is similar to `wcschr'. But it returns a pointer to
217 the closing NUL wide character in case C is not found in S. */
218extern wchar_t *wcschrnul (const wchar_t *__s, wchar_t __wc)
219 __THROW __attribute_pure__;
220#endif
221
222/* Return the length of the initial segmet of WCS which
223 consists entirely of wide characters not in REJECT. */
224extern size_t wcscspn (const wchar_t *__wcs, const wchar_t *__reject)
225 __THROW __attribute_pure__;
226/* Return the length of the initial segmet of WCS which
227 consists entirely of wide characters in ACCEPT. */
228extern size_t wcsspn (const wchar_t *__wcs, const wchar_t *__accept)
229 __THROW __attribute_pure__;
230/* Find the first occurrence in WCS of any character in ACCEPT. */
231#ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
232extern "C++" wchar_t *wcspbrk (wchar_t *__wcs, const wchar_t *__accept)
233 __THROW __asm ("wcspbrk") __attribute_pure__;
234extern "C++" const wchar_t *wcspbrk (const wchar_t *__wcs,
235 const wchar_t *__accept)
236 __THROW __asm ("wcspbrk") __attribute_pure__;
237#else
238extern wchar_t *wcspbrk (const wchar_t *__wcs, const wchar_t *__accept)
239 __THROW __attribute_pure__;
240# if __GLIBC_USE (ISOC23) && defined __glibc_const_generic && !defined _LIBC
241# define wcspbrk(WCS, ACCEPT) \
242 __glibc_const_generic (WCS, const wchar_t *, wcspbrk (WCS, ACCEPT))
243# endif
244#endif
245/* Find the first occurrence of NEEDLE in HAYSTACK. */
246#ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
247extern "C++" wchar_t *wcsstr (wchar_t *__haystack, const wchar_t *__needle)
248 __THROW __asm ("wcsstr") __attribute_pure__;
249extern "C++" const wchar_t *wcsstr (const wchar_t *__haystack,
250 const wchar_t *__needle)
251 __THROW __asm ("wcsstr") __attribute_pure__;
252#else
253extern wchar_t *wcsstr (const wchar_t *__haystack, const wchar_t *__needle)
254 __THROW __attribute_pure__;
255# if __GLIBC_USE (ISOC23) && defined __glibc_const_generic && !defined _LIBC
256# define wcsstr(HAYSTACK, NEEDLE) \
257 __glibc_const_generic (HAYSTACK, const wchar_t *, \
258 wcsstr (HAYSTACK, NEEDLE))
259# endif
260#endif
261
262/* Divide WCS into tokens separated by characters in DELIM. */
263extern wchar_t *wcstok (wchar_t *__restrict __s,
264 const wchar_t *__restrict __delim,
265 wchar_t **__restrict __ptr) __THROW;
266
267/* Return the number of wide characters in S. */
268extern size_t wcslen (const wchar_t *__s) __THROW __attribute_pure__;
269
270#ifdef __USE_XOPEN
271/* Another name for `wcsstr' from XPG4. */
272# ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
273extern "C++" wchar_t *wcswcs (wchar_t *__haystack, const wchar_t *__needle)
274 __THROW __asm ("wcswcs") __attribute_pure__;
275extern "C++" const wchar_t *wcswcs (const wchar_t *__haystack,
276 const wchar_t *__needle)
277 __THROW __asm ("wcswcs") __attribute_pure__;
278# else
279extern wchar_t *wcswcs (const wchar_t *__haystack, const wchar_t *__needle)
280 __THROW __attribute_pure__;
281# endif
282#endif
283
284#ifdef __USE_XOPEN2K8
285/* Return the number of wide characters in S, but at most MAXLEN. */
286extern size_t wcsnlen (const wchar_t *__s, size_t __maxlen)
287 __THROW __attribute_pure__;
288#endif
289
290
291/* Search N wide characters of S for C. */
292#ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO
293extern "C++" wchar_t *wmemchr (wchar_t *__s, wchar_t __c, size_t __n)
294 __THROW __asm ("wmemchr") __attribute_pure__;
295extern "C++" const wchar_t *wmemchr (const wchar_t *__s, wchar_t __c,
296 size_t __n)
297 __THROW __asm ("wmemchr") __attribute_pure__;
298#else
299extern wchar_t *wmemchr (const wchar_t *__s, wchar_t __c, size_t __n)
300 __THROW __attribute_pure__;
301# if __GLIBC_USE (ISOC23) && defined __glibc_const_generic && !defined _LIBC
302# define wmemchr(S, C, N) \
303 __glibc_const_generic (S, const wchar_t *, wmemchr (S, C, N))
304# endif
305#endif
306
307/* Compare N wide characters of S1 and S2. */
308extern int wmemcmp (const wchar_t *__s1, const wchar_t *__s2, size_t __n)
309 __THROW __attribute_pure__;
310
311/* Copy N wide characters of SRC to DEST. */
312extern wchar_t *wmemcpy (wchar_t *__restrict __s1,
313 const wchar_t *__restrict __s2, size_t __n) __THROW;
314
315/* Copy N wide characters of SRC to DEST, guaranteeing
316 correct behavior for overlapping strings. */
317extern wchar_t *wmemmove (wchar_t *__s1, const wchar_t *__s2, size_t __n)
318 __THROW;
319
320/* Set N wide characters of S to C. */
321extern wchar_t *wmemset (wchar_t *__s, wchar_t __c, size_t __n) __THROW;
322
323#ifdef __USE_GNU
324/* Copy N wide characters of SRC to DEST and return pointer to following
325 wide character. */
326extern wchar_t *wmempcpy (wchar_t *__restrict __s1,
327 const wchar_t *__restrict __s2, size_t __n)
328 __THROW;
329#endif
330
331
332/* Determine whether C constitutes a valid (one-byte) multibyte
333 character. */
334extern wint_t btowc (int __c) __THROW;
335
336/* Determine whether C corresponds to a member of the extended
337 character set whose multibyte representation is a single byte. */
338extern int wctob (wint_t __c) __THROW;
339
340/* Determine whether PS points to an object representing the initial
341 state. */
342extern int mbsinit (const mbstate_t *__ps) __THROW __attribute_pure__;
343
344/* Write wide character representation of multibyte character pointed
345 to by S to PWC. */
346extern size_t mbrtowc (wchar_t *__restrict __pwc,
347 const char *__restrict __s, size_t __n,
348 mbstate_t *__restrict __p) __THROW;
349
350/* Write multibyte representation of wide character WC to S. */
351extern size_t wcrtomb (char *__restrict __s, wchar_t __wc,
352 mbstate_t *__restrict __ps) __THROW;
353
354/* Return number of bytes in multibyte character pointed to by S. */
355extern size_t __mbrlen (const char *__restrict __s, size_t __n,
356 mbstate_t *__restrict __ps) __THROW;
357extern size_t mbrlen (const char *__restrict __s, size_t __n,
358 mbstate_t *__restrict __ps) __THROW;
359
360#ifdef __USE_EXTERN_INLINES
361/* Define inline function as optimization. */
362
363/* We can use the BTOWC and WCTOB optimizations since we know that all
364 locales must use ASCII encoding for the values in the ASCII range
365 and because the wchar_t encoding is always ISO 10646. */
366extern wint_t __btowc_alias (int __c) __asm ("btowc");
367__extern_inline wint_t
368__NTH (btowc (int __c))
369{ return (__builtin_constant_p (__c) && __c >= '\0' && __c <= '\x7f'
370 ? (wint_t) __c : __btowc_alias (__c)); }
371
372extern int __wctob_alias (wint_t __c) __asm ("wctob");
373__extern_inline int
374__NTH (wctob (wint_t __wc))
375{ return (__builtin_constant_p (__wc) && __wc >= L'\0' && __wc <= L'\x7f'
376 ? (int) __wc : __wctob_alias (__wc)); }
377
378__extern_inline size_t
379__NTH (mbrlen (const char *__restrict __s, size_t __n,
380 mbstate_t *__restrict __ps))
381{ return (__ps != NULL
382 ? mbrtowc (NULL, __s, __n, __ps) : __mbrlen (__s, __n, NULL)); }
383#endif
384
385/* Write wide character representation of multibyte character string
386 SRC to DST. */
387extern size_t mbsrtowcs (wchar_t *__restrict __dst,
388 const char **__restrict __src, size_t __len,
389 mbstate_t *__restrict __ps) __THROW;
390
391/* Write multibyte character representation of wide character string
392 SRC to DST. */
393extern size_t wcsrtombs (char *__restrict __dst,
394 const wchar_t **__restrict __src, size_t __len,
395 mbstate_t *__restrict __ps) __THROW;
396
397
398#ifdef __USE_XOPEN2K8
399/* Write wide character representation of at most NMC bytes of the
400 multibyte character string SRC to DST. */
401extern size_t mbsnrtowcs (wchar_t *__restrict __dst,
402 const char **__restrict __src, size_t __nmc,
403 size_t __len, mbstate_t *__restrict __ps) __THROW;
404
405/* Write multibyte character representation of at most NWC characters
406 from the wide character string SRC to DST. */
407extern size_t wcsnrtombs (char *__restrict __dst,
408 const wchar_t **__restrict __src,
409 size_t __nwc, size_t __len,
410 mbstate_t *__restrict __ps) __THROW;
411#endif /* use POSIX 2008 */
412
413
414/* The following functions are extensions found in X/Open CAE. */
415#ifdef __USE_XOPEN
416/* Determine number of column positions required for C. */
417extern int wcwidth (wchar_t __c) __THROW;
418
419/* Determine number of column positions required for first N wide
420 characters (or fewer if S ends before this) in S. */
421extern int wcswidth (const wchar_t *__s, size_t __n) __THROW;
422#endif /* Use X/Open. */
423
424
425/* Convert initial portion of the wide string NPTR to `double'
426 representation. */
427extern double wcstod (const wchar_t *__restrict __nptr,
428 wchar_t **__restrict __endptr) __THROW;
429
430#ifdef __USE_ISOC99
431/* Likewise for `float' and `long double' sizes of floating-point numbers. */
432extern float wcstof (const wchar_t *__restrict __nptr,
433 wchar_t **__restrict __endptr) __THROW;
434extern long double wcstold (const wchar_t *__restrict __nptr,
435 wchar_t **__restrict __endptr) __THROW;
436#endif /* C99 */
437
438#if __GLIBC_USE (IEC_60559_TYPES_EXT) && __GLIBC_USE (ISOC23)
439/* Likewise for `_FloatN' and `_FloatNx' when support is enabled. */
440
441# if __HAVE_FLOAT16
442extern _Float16 wcstof16 (const wchar_t *__restrict __nptr,
443 wchar_t **__restrict __endptr) __THROW;
444# endif
445
446# if __HAVE_FLOAT32
447extern _Float32 wcstof32 (const wchar_t *__restrict __nptr,
448 wchar_t **__restrict __endptr) __THROW;
449# endif
450
451# if __HAVE_FLOAT64
452extern _Float64 wcstof64 (const wchar_t *__restrict __nptr,
453 wchar_t **__restrict __endptr) __THROW;
454# endif
455
456# if __HAVE_FLOAT128
457extern _Float128 wcstof128 (const wchar_t *__restrict __nptr,
458 wchar_t **__restrict __endptr) __THROW;
459# endif
460
461# if __HAVE_FLOAT32X
462extern _Float32x wcstof32x (const wchar_t *__restrict __nptr,
463 wchar_t **__restrict __endptr) __THROW;
464# endif
465
466# if __HAVE_FLOAT64X
467extern _Float64x wcstof64x (const wchar_t *__restrict __nptr,
468 wchar_t **__restrict __endptr) __THROW;
469# endif
470
471# if __HAVE_FLOAT128X
472extern _Float128x wcstof128x (const wchar_t *__restrict __nptr,
473 wchar_t **__restrict __endptr) __THROW;
474# endif
475#endif /* __GLIBC_USE (IEC_60559_TYPES_EXT) && __GLIBC_USE (ISOC23) */
476
477
478/* Convert initial portion of wide string NPTR to `long int'
479 representation. */
480extern long int wcstol (const wchar_t *__restrict __nptr,
481 wchar_t **__restrict __endptr, int __base) __THROW;
482
483/* Convert initial portion of wide string NPTR to `unsigned long int'
484 representation. */
485extern unsigned long int wcstoul (const wchar_t *__restrict __nptr,
486 wchar_t **__restrict __endptr, int __base)
487 __THROW;
488
489#ifdef __USE_ISOC99
490/* Convert initial portion of wide string NPTR to `long long int'
491 representation. */
492__extension__
493extern long long int wcstoll (const wchar_t *__restrict __nptr,
494 wchar_t **__restrict __endptr, int __base)
495 __THROW;
496
497/* Convert initial portion of wide string NPTR to `unsigned long long int'
498 representation. */
499__extension__
500extern unsigned long long int wcstoull (const wchar_t *__restrict __nptr,
501 wchar_t **__restrict __endptr,
502 int __base) __THROW;
503#endif /* ISO C99. */
504
505#ifdef __USE_GNU
506/* Convert initial portion of wide string NPTR to `long long int'
507 representation. */
508__extension__
509extern long long int wcstoq (const wchar_t *__restrict __nptr,
510 wchar_t **__restrict __endptr, int __base)
511 __THROW;
512
513/* Convert initial portion of wide string NPTR to `unsigned long long int'
514 representation. */
515__extension__
516extern unsigned long long int wcstouq (const wchar_t *__restrict __nptr,
517 wchar_t **__restrict __endptr,
518 int __base) __THROW;
519#endif /* Use GNU. */
520
521/* Versions of the above functions that handle '0b' and '0B' prefixes
522 in base 0 or 2. */
523#if __GLIBC_USE (C23_STRTOL)
524# ifdef __REDIRECT
525extern long int __REDIRECT_NTH (wcstol, (const wchar_t *__restrict __nptr,
526 wchar_t **__restrict __endptr,
527 int __base), __isoc23_wcstol);
528extern unsigned long int __REDIRECT_NTH (wcstoul,
529 (const wchar_t *__restrict __nptr,
530 wchar_t **__restrict __endptr,
531 int __base), __isoc23_wcstoul);
532__extension__
533extern long long int __REDIRECT_NTH (wcstoll,
534 (const wchar_t *__restrict __nptr,
535 wchar_t **__restrict __endptr,
536 int __base), __isoc23_wcstoll);
537__extension__
538extern unsigned long long int __REDIRECT_NTH (wcstoull,
539 (const wchar_t *__restrict __nptr,
540 wchar_t **__restrict __endptr,
541 int __base), __isoc23_wcstoull);
542# ifdef __USE_GNU
543__extension__
544extern long long int __REDIRECT_NTH (wcstoq, (const wchar_t *__restrict __nptr,
545 wchar_t **__restrict __endptr,
546 int __base), __isoc23_wcstoll);
547__extension__
548extern unsigned long long int __REDIRECT_NTH (wcstouq,
549 (const wchar_t *__restrict __nptr,
550 wchar_t **__restrict __endptr,
551 int __base), __isoc23_wcstoull);
552# endif
553# else
554extern long int __isoc23_wcstol (const wchar_t *__restrict __nptr,
555 wchar_t **__restrict __endptr, int __base)
556 __THROW;
557extern unsigned long int __isoc23_wcstoul (const wchar_t *__restrict __nptr,
558 wchar_t **__restrict __endptr,
559 int __base)
560 __THROW;
561__extension__
562extern long long int __isoc23_wcstoll (const wchar_t *__restrict __nptr,
563 wchar_t **__restrict __endptr,
564 int __base)
565 __THROW;
566__extension__
567extern unsigned long long int __isoc23_wcstoull (const wchar_t *__restrict __nptr,
568 wchar_t **__restrict __endptr,
569 int __base)
570 __THROW;
571# define wcstol __isoc23_wcstol
572# define wcstoul __isoc23_wcstoul
573# define wcstoll __isoc23_wcstoll
574# define wcstoull __isoc23_wcstoull
575# ifdef __USE_GNU
576# define wcstoq __isoc23_wcstoll
577# define wcstouq __isoc23_wcstoull
578# endif
579# endif
580#endif
581
582#ifdef __USE_GNU
583/* Parallel versions of the functions above which take the locale to
584 use as an additional parameter. These are GNU extensions inspired
585 by the POSIX.1-2008 extended locale API. */
586extern long int wcstol_l (const wchar_t *__restrict __nptr,
587 wchar_t **__restrict __endptr, int __base,
588 locale_t __loc) __THROW;
589
590extern unsigned long int wcstoul_l (const wchar_t *__restrict __nptr,
591 wchar_t **__restrict __endptr,
592 int __base, locale_t __loc) __THROW;
593
594__extension__
595extern long long int wcstoll_l (const wchar_t *__restrict __nptr,
596 wchar_t **__restrict __endptr,
597 int __base, locale_t __loc) __THROW;
598
599__extension__
600extern unsigned long long int wcstoull_l (const wchar_t *__restrict __nptr,
601 wchar_t **__restrict __endptr,
602 int __base, locale_t __loc)
603 __THROW;
604
605/* Versions of the above functions that handle '0b' and '0B' prefixes
606 in base 0 or 2. */
607# if __GLIBC_USE (C23_STRTOL)
608# ifdef __REDIRECT
609extern long int __REDIRECT_NTH (wcstol_l, (const wchar_t *__restrict __nptr,
610 wchar_t **__restrict __endptr,
611 int __base, locale_t __loc),
612 __isoc23_wcstol_l);
613extern unsigned long int __REDIRECT_NTH (wcstoul_l,
614 (const wchar_t *__restrict __nptr,
615 wchar_t **__restrict __endptr,
616 int __base, locale_t __loc),
617 __isoc23_wcstoul_l);
618__extension__
619extern long long int __REDIRECT_NTH (wcstoll_l,
620 (const wchar_t *__restrict __nptr,
621 wchar_t **__restrict __endptr,
622 int __base, locale_t __loc),
623 __isoc23_wcstoll_l);
624__extension__
625extern unsigned long long int __REDIRECT_NTH (wcstoull_l,
626 (const wchar_t *__restrict __nptr,
627 wchar_t **__restrict __endptr,
628 int __base, locale_t __loc),
629 __isoc23_wcstoull_l);
630# else
631extern long int __isoc23_wcstol_l (const wchar_t *__restrict __nptr,
632 wchar_t **__restrict __endptr, int __base,
633 locale_t __loc) __THROW;
634extern unsigned long int __isoc23_wcstoul_l (const wchar_t *__restrict __nptr,
635 wchar_t **__restrict __endptr,
636 int __base, locale_t __loc)
637 __THROW;
638__extension__
639extern long long int __isoc23_wcstoll_l (const wchar_t *__restrict __nptr,
640 wchar_t **__restrict __endptr,
641 int __base, locale_t __loc)
642 __THROW;
643__extension__
644extern unsigned long long int __isoc23_wcstoull_l (const wchar_t *__restrict __nptr,
645 wchar_t **__restrict __endptr,
646 int __base, locale_t __loc)
647 __THROW;
648# define wcstol_l __isoc23_wcstol_l
649# define wcstoul_l __isoc23_wcstoul_l
650# define wcstoll_l __isoc23_wcstoll_l
651# define wcstoull_l __isoc23_wcstoull_l
652# endif
653# endif
654
655extern double wcstod_l (const wchar_t *__restrict __nptr,
656 wchar_t **__restrict __endptr, locale_t __loc)
657 __THROW;
658
659extern float wcstof_l (const wchar_t *__restrict __nptr,
660 wchar_t **__restrict __endptr, locale_t __loc)
661 __THROW;
662
663extern long double wcstold_l (const wchar_t *__restrict __nptr,
664 wchar_t **__restrict __endptr,
665 locale_t __loc) __THROW;
666
667# if __HAVE_FLOAT16
668extern _Float16 wcstof16_l (const wchar_t *__restrict __nptr,
669 wchar_t **__restrict __endptr,
670 locale_t __loc) __THROW;
671# endif
672
673# if __HAVE_FLOAT32
674extern _Float32 wcstof32_l (const wchar_t *__restrict __nptr,
675 wchar_t **__restrict __endptr,
676 locale_t __loc) __THROW;
677# endif
678
679# if __HAVE_FLOAT64
680extern _Float64 wcstof64_l (const wchar_t *__restrict __nptr,
681 wchar_t **__restrict __endptr,
682 locale_t __loc) __THROW;
683# endif
684
685# if __HAVE_FLOAT128
686extern _Float128 wcstof128_l (const wchar_t *__restrict __nptr,
687 wchar_t **__restrict __endptr,
688 locale_t __loc) __THROW;
689# endif
690
691# if __HAVE_FLOAT32X
692extern _Float32x wcstof32x_l (const wchar_t *__restrict __nptr,
693 wchar_t **__restrict __endptr,
694 locale_t __loc) __THROW;
695# endif
696
697# if __HAVE_FLOAT64X
698extern _Float64x wcstof64x_l (const wchar_t *__restrict __nptr,
699 wchar_t **__restrict __endptr,
700 locale_t __loc) __THROW;
701# endif
702
703# if __HAVE_FLOAT128X
704extern _Float128x wcstof128x_l (const wchar_t *__restrict __nptr,
705 wchar_t **__restrict __endptr,
706 locale_t __loc) __THROW;
707# endif
708#endif /* use GNU */
709
710
711#ifdef __USE_XOPEN2K8
712/* Copy SRC to DEST, returning the address of the terminating L'\0' in
713 DEST. */
714extern wchar_t *wcpcpy (wchar_t *__restrict __dest,
715 const wchar_t *__restrict __src) __THROW;
716
717/* Copy no more than N characters of SRC to DEST, returning the address of
718 the last character written into DEST. */
719extern wchar_t *wcpncpy (wchar_t *__restrict __dest,
720 const wchar_t *__restrict __src, size_t __n)
721 __THROW;
722#endif
723
724
725/* Wide character I/O functions. */
726
727#if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
728# ifndef __attr_dealloc_fclose
729# if defined __has_builtin
730# if __has_builtin (__builtin_fclose)
731/* If the attribute macro hasn't been defined yet (by <stdio.h>) and
732 fclose is a built-in, use it. */
733# define __attr_dealloc_fclose __attr_dealloc (__builtin_fclose, 1)
734# endif
735# endif
736# endif
737# ifndef __attr_dealloc_fclose
738# define __attr_dealloc_fclose /* empty */
739# endif
740
741/* Like OPEN_MEMSTREAM, but the stream is wide oriented and produces
742 a wide character string. */
743extern __FILE *open_wmemstream (wchar_t **__bufloc, size_t *__sizeloc) __THROW
744 __attribute_malloc__ __attr_dealloc_fclose;
745#endif
746
747#if defined __USE_ISOC95 || defined __USE_UNIX98
748
749/* Select orientation for stream. */
750extern int fwide (__FILE *__fp, int __mode) __THROW;
751
752
753/* Write formatted output to STREAM.
754
755 This function is a possible cancellation point and therefore not
756 marked with __THROW. */
757extern int fwprintf (__FILE *__restrict __stream,
758 const wchar_t *__restrict __format, ...)
759 /* __attribute__ ((__format__ (__wprintf__, 2, 3))) */;
760/* Write formatted output to stdout.
761
762 This function is a possible cancellation point and therefore not
763 marked with __THROW. */
764extern int wprintf (const wchar_t *__restrict __format, ...)
765 /* __attribute__ ((__format__ (__wprintf__, 1, 2))) */;
766/* Write formatted output of at most N characters to S. */
767extern int swprintf (wchar_t *__restrict __s, size_t __n,
768 const wchar_t *__restrict __format, ...)
769 __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 4))) */;
770
771/* Write formatted output to S from argument list ARG.
772
773 This function is a possible cancellation point and therefore not
774 marked with __THROW. */
775extern int vfwprintf (__FILE *__restrict __s,
776 const wchar_t *__restrict __format,
777 __gnuc_va_list __arg)
778 /* __attribute__ ((__format__ (__wprintf__, 2, 0))) */;
779/* Write formatted output to stdout from argument list ARG.
780
781 This function is a possible cancellation point and therefore not
782 marked with __THROW. */
783extern int vwprintf (const wchar_t *__restrict __format,
784 __gnuc_va_list __arg)
785 /* __attribute__ ((__format__ (__wprintf__, 1, 0))) */;
786/* Write formatted output of at most N character to S from argument
787 list ARG. */
788extern int vswprintf (wchar_t *__restrict __s, size_t __n,
789 const wchar_t *__restrict __format,
790 __gnuc_va_list __arg)
791 __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 0))) */;
792
793
794/* Read formatted input from STREAM.
795
796 This function is a possible cancellation point and therefore not
797 marked with __THROW. */
798extern int fwscanf (__FILE *__restrict __stream,
799 const wchar_t *__restrict __format, ...)
800 /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
801/* Read formatted input from stdin.
802
803 This function is a possible cancellation point and therefore not
804 marked with __THROW. */
805extern int wscanf (const wchar_t *__restrict __format, ...)
806 /* __attribute__ ((__format__ (__wscanf__, 1, 2))) */;
807/* Read formatted input from S. */
808extern int swscanf (const wchar_t *__restrict __s,
809 const wchar_t *__restrict __format, ...)
810 __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
811
812/* For historical reasons, the C99-compliant versions of the scanf
813 functions are at alternative names. When __LDBL_COMPAT or
814 __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI are in effect, this is handled in
815 bits/wchar-ldbl.h. */
816# if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT \
817 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
818# if __GLIBC_USE (C23_STRTOL)
819# ifdef __REDIRECT
820extern int __REDIRECT (fwscanf, (__FILE *__restrict __stream,
821 const wchar_t *__restrict __format, ...),
822 __isoc23_fwscanf)
823 /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
824extern int __REDIRECT (wscanf, (const wchar_t *__restrict __format, ...),
825 __isoc23_wscanf)
826 /* __attribute__ ((__format__ (__wscanf__, 1, 2))) */;
827extern int __REDIRECT_NTH (swscanf, (const wchar_t *__restrict __s,
828 const wchar_t *__restrict __format,
829 ...), __isoc23_swscanf)
830 /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
831# else
832extern int __isoc23_fwscanf (__FILE *__restrict __stream,
833 const wchar_t *__restrict __format, ...);
834extern int __isoc23_wscanf (const wchar_t *__restrict __format, ...);
835extern int __isoc23_swscanf (const wchar_t *__restrict __s,
836 const wchar_t *__restrict __format, ...)
837 __THROW;
838# define fwscanf __isoc23_fwscanf
839# define wscanf __isoc23_wscanf
840# define swscanf __isoc23_swscanf
841# endif
842# else
843# ifdef __REDIRECT
844extern int __REDIRECT (fwscanf, (__FILE *__restrict __stream,
845 const wchar_t *__restrict __format, ...),
846 __isoc99_fwscanf)
847 /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
848extern int __REDIRECT (wscanf, (const wchar_t *__restrict __format, ...),
849 __isoc99_wscanf)
850 /* __attribute__ ((__format__ (__wscanf__, 1, 2))) */;
851extern int __REDIRECT_NTH (swscanf, (const wchar_t *__restrict __s,
852 const wchar_t *__restrict __format,
853 ...), __isoc99_swscanf)
854 /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
855# else
856extern int __isoc99_fwscanf (__FILE *__restrict __stream,
857 const wchar_t *__restrict __format, ...);
858extern int __isoc99_wscanf (const wchar_t *__restrict __format, ...);
859extern int __isoc99_swscanf (const wchar_t *__restrict __s,
860 const wchar_t *__restrict __format, ...)
861 __THROW;
862# define fwscanf __isoc99_fwscanf
863# define wscanf __isoc99_wscanf
864# define swscanf __isoc99_swscanf
865# endif
866# endif
867# endif
868
869#endif /* Use ISO C95, C99 and Unix98. */
870
871#ifdef __USE_ISOC99
872/* Read formatted input from S into argument list ARG.
873
874 This function is a possible cancellation point and therefore not
875 marked with __THROW. */
876extern int vfwscanf (__FILE *__restrict __s,
877 const wchar_t *__restrict __format,
878 __gnuc_va_list __arg)
879 /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
880/* Read formatted input from stdin into argument list ARG.
881
882 This function is a possible cancellation point and therefore not
883 marked with __THROW. */
884extern int vwscanf (const wchar_t *__restrict __format,
885 __gnuc_va_list __arg)
886 /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */;
887/* Read formatted input from S into argument list ARG. */
888extern int vswscanf (const wchar_t *__restrict __s,
889 const wchar_t *__restrict __format,
890 __gnuc_va_list __arg)
891 __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
892
893/* Same redirection as above for the v*wscanf family. */
894# if !__GLIBC_USE (DEPRECATED_SCANF) \
895 && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
896 && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K) \
897 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
898# if __GLIBC_USE (C23_STRTOL)
899# ifdef __REDIRECT
900extern int __REDIRECT (vfwscanf, (__FILE *__restrict __s,
901 const wchar_t *__restrict __format,
902 __gnuc_va_list __arg), __isoc23_vfwscanf)
903 /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
904extern int __REDIRECT (vwscanf, (const wchar_t *__restrict __format,
905 __gnuc_va_list __arg), __isoc23_vwscanf)
906 /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */;
907extern int __REDIRECT_NTH (vswscanf, (const wchar_t *__restrict __s,
908 const wchar_t *__restrict __format,
909 __gnuc_va_list __arg), __isoc23_vswscanf)
910 /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
911# else
912extern int __isoc23_vfwscanf (__FILE *__restrict __s,
913 const wchar_t *__restrict __format,
914 __gnuc_va_list __arg);
915extern int __isoc23_vwscanf (const wchar_t *__restrict __format,
916 __gnuc_va_list __arg);
917extern int __isoc23_vswscanf (const wchar_t *__restrict __s,
918 const wchar_t *__restrict __format,
919 __gnuc_va_list __arg) __THROW;
920# define vfwscanf __isoc23_vfwscanf
921# define vwscanf __isoc23_vwscanf
922# define vswscanf __isoc23_vswscanf
923# endif
924# else
925# ifdef __REDIRECT
926extern int __REDIRECT (vfwscanf, (__FILE *__restrict __s,
927 const wchar_t *__restrict __format,
928 __gnuc_va_list __arg), __isoc99_vfwscanf)
929 /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
930extern int __REDIRECT (vwscanf, (const wchar_t *__restrict __format,
931 __gnuc_va_list __arg), __isoc99_vwscanf)
932 /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */;
933extern int __REDIRECT_NTH (vswscanf, (const wchar_t *__restrict __s,
934 const wchar_t *__restrict __format,
935 __gnuc_va_list __arg), __isoc99_vswscanf)
936 /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
937# else
938extern int __isoc99_vfwscanf (__FILE *__restrict __s,
939 const wchar_t *__restrict __format,
940 __gnuc_va_list __arg);
941extern int __isoc99_vwscanf (const wchar_t *__restrict __format,
942 __gnuc_va_list __arg);
943extern int __isoc99_vswscanf (const wchar_t *__restrict __s,
944 const wchar_t *__restrict __format,
945 __gnuc_va_list __arg) __THROW;
946# define vfwscanf __isoc99_vfwscanf
947# define vwscanf __isoc99_vwscanf
948# define vswscanf __isoc99_vswscanf
949# endif
950# endif
951# endif
952
953#endif /* Use ISO C99. */
954
955
956/* Read a character from STREAM.
957
958 These functions are possible cancellation points and therefore not
959 marked with __THROW. */
960extern wint_t fgetwc (__FILE *__stream);
961extern wint_t getwc (__FILE *__stream);
962
963/* Read a character from stdin.
964
965 This function is a possible cancellation point and therefore not
966 marked with __THROW. */
967extern wint_t getwchar (void);
968
969
970/* Write a character to STREAM.
971
972 These functions are possible cancellation points and therefore not
973 marked with __THROW. */
974extern wint_t fputwc (wchar_t __wc, __FILE *__stream);
975extern wint_t putwc (wchar_t __wc, __FILE *__stream);
976
977/* Write a character to stdout.
978
979 This function is a possible cancellation point and therefore not
980 marked with __THROW. */
981extern wint_t putwchar (wchar_t __wc);
982
983
984/* Get a newline-terminated wide character string of finite length
985 from STREAM.
986
987 This function is a possible cancellation point and therefore not
988 marked with __THROW. */
989extern wchar_t *fgetws (wchar_t *__restrict __ws, int __n,
990 __FILE *__restrict __stream);
991
992/* Write a string to STREAM.
993
994 This function is a possible cancellation point and therefore not
995 marked with __THROW. */
996extern int fputws (const wchar_t *__restrict __ws,
997 __FILE *__restrict __stream);
998
999
1000/* Push a character back onto the input buffer of STREAM.
1001
1002 This function is a possible cancellation point and therefore not
1003 marked with __THROW. */
1004extern wint_t ungetwc (wint_t __wc, __FILE *__stream);
1005
1006
1007#ifdef __USE_GNU
1008/* These are defined to be equivalent to the `char' functions defined
1009 in POSIX.1:1996.
1010
1011 These functions are not part of POSIX and therefore no official
1012 cancellation point. But due to similarity with an POSIX interface
1013 or due to the implementation they are cancellation points and
1014 therefore not marked with __THROW. */
1015extern wint_t getwc_unlocked (__FILE *__stream);
1016extern wint_t getwchar_unlocked (void);
1017
1018/* This is the wide character version of a GNU extension.
1019
1020 This function is not part of POSIX and therefore no official
1021 cancellation point. But due to similarity with an POSIX interface
1022 or due to the implementation it is a cancellation point and
1023 therefore not marked with __THROW. */
1024extern wint_t fgetwc_unlocked (__FILE *__stream);
1025
1026/* Faster version when locking is not necessary.
1027
1028 This function is not part of POSIX and therefore no official
1029 cancellation point. But due to similarity with an POSIX interface
1030 or due to the implementation it is a cancellation point and
1031 therefore not marked with __THROW. */
1032extern wint_t fputwc_unlocked (wchar_t __wc, __FILE *__stream);
1033
1034/* These are defined to be equivalent to the `char' functions defined
1035 in POSIX.1:1996.
1036
1037 These functions are not part of POSIX and therefore no official
1038 cancellation point. But due to similarity with an POSIX interface
1039 or due to the implementation they are cancellation points and
1040 therefore not marked with __THROW. */
1041extern wint_t putwc_unlocked (wchar_t __wc, __FILE *__stream);
1042extern wint_t putwchar_unlocked (wchar_t __wc);
1043
1044
1045/* This function does the same as `fgetws' but does not lock the stream.
1046
1047 This function is not part of POSIX and therefore no official
1048 cancellation point. But due to similarity with an POSIX interface
1049 or due to the implementation it is a cancellation point and
1050 therefore not marked with __THROW. */
1051extern wchar_t *fgetws_unlocked (wchar_t *__restrict __ws, int __n,
1052 __FILE *__restrict __stream);
1053
1054/* This function does the same as `fputws' but does not lock the stream.
1055
1056 This function is not part of POSIX and therefore no official
1057 cancellation point. But due to similarity with an POSIX interface
1058 or due to the implementation it is a cancellation point and
1059 therefore not marked with __THROW. */
1060extern int fputws_unlocked (const wchar_t *__restrict __ws,
1061 __FILE *__restrict __stream);
1062#endif
1063
1064
1065/* Format TP into S according to FORMAT.
1066 Write no more than MAXSIZE wide characters and return the number
1067 of wide characters written, or 0 if it would exceed MAXSIZE. */
1068extern size_t wcsftime (wchar_t *__restrict __s, size_t __maxsize,
1069 const wchar_t *__restrict __format,
1070 const struct tm *__restrict __tp) __THROW;
1071
1072# ifdef __USE_GNU
1073/* Similar to `wcsftime' but takes the information from
1074 the provided locale and not the global locale. */
1075extern size_t wcsftime_l (wchar_t *__restrict __s, size_t __maxsize,
1076 const wchar_t *__restrict __format,
1077 const struct tm *__restrict __tp,
1078 locale_t __loc) __THROW;
1079# endif
1080
1081/* Define some macros helping to catch buffer overflows. */
1082#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
1083/* Declare all functions from bits/wchar2-decl.h first. */
1084# include <bits/wchar2-decl.h>
1085#endif
1086
1087/* The following headers provide asm redirections. These redirections must
1088 appear before the first usage of these functions, e.g. in bits/wchar.h. */
1089#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
1090# include <bits/wchar-ldbl.h>
1091#endif
1092
1093#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
1094/* Now include the function definitions and redirects too. */
1095# include <bits/wchar2.h>
1096#endif
1097
1098__END_DECLS
1099
1100#endif /* wchar.h */
1101