10b57cec5SDimitry Andric // -*- C++ -*-
2349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric //
40b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric //
80b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric 
100b57cec5SDimitry Andric #if defined(__need_wint_t) || defined(__need_mbstate_t)
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
130b57cec5SDimitry Andric #    pragma GCC system_header
140b57cec5SDimitry Andric #  endif
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #  include_next <wchar.h>
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #elif !defined(_LIBCPP_WCHAR_H)
190b57cec5SDimitry Andric #  define _LIBCPP_WCHAR_H
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric /*
220b57cec5SDimitry Andric     wchar.h synopsis
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric Macros:
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric     NULL
270b57cec5SDimitry Andric     WCHAR_MAX
280b57cec5SDimitry Andric     WCHAR_MIN
290b57cec5SDimitry Andric     WEOF
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric Types:
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric     mbstate_t
340b57cec5SDimitry Andric     size_t
350b57cec5SDimitry Andric     tm
360b57cec5SDimitry Andric     wint_t
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...);
390b57cec5SDimitry Andric int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...);
400b57cec5SDimitry Andric int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, ...);
410b57cec5SDimitry Andric int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...);
420b57cec5SDimitry Andric int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg);
430b57cec5SDimitry Andric int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list arg);  // C99
440b57cec5SDimitry Andric int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, va_list arg);
450b57cec5SDimitry Andric int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, va_list arg);  // C99
460b57cec5SDimitry Andric int vwprintf(const wchar_t* restrict format, va_list arg);
470b57cec5SDimitry Andric int vwscanf(const wchar_t* restrict format, va_list arg);  // C99
480b57cec5SDimitry Andric int wprintf(const wchar_t* restrict format, ...);
490b57cec5SDimitry Andric int wscanf(const wchar_t* restrict format, ...);
500b57cec5SDimitry Andric wint_t fgetwc(FILE* stream);
510b57cec5SDimitry Andric wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream);
520b57cec5SDimitry Andric wint_t fputwc(wchar_t c, FILE* stream);
530b57cec5SDimitry Andric int fputws(const wchar_t* restrict s, FILE* restrict stream);
540b57cec5SDimitry Andric int fwide(FILE* stream, int mode);
550b57cec5SDimitry Andric wint_t getwc(FILE* stream);
560b57cec5SDimitry Andric wint_t getwchar();
570b57cec5SDimitry Andric wint_t putwc(wchar_t c, FILE* stream);
580b57cec5SDimitry Andric wint_t putwchar(wchar_t c);
590b57cec5SDimitry Andric wint_t ungetwc(wint_t c, FILE* stream);
600b57cec5SDimitry Andric double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr);
610b57cec5SDimitry Andric float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr);         // C99
620b57cec5SDimitry Andric long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr);  // C99
630b57cec5SDimitry Andric long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
640b57cec5SDimitry Andric long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);  // C99
650b57cec5SDimitry Andric unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
660b57cec5SDimitry Andric unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);  // C99
670b57cec5SDimitry Andric wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2);
680b57cec5SDimitry Andric wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
690b57cec5SDimitry Andric wchar_t* wcscat(wchar_t* restrict s1, const wchar_t* restrict s2);
700b57cec5SDimitry Andric wchar_t* wcsncat(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
710b57cec5SDimitry Andric int wcscmp(const wchar_t* s1, const wchar_t* s2);
720b57cec5SDimitry Andric int wcscoll(const wchar_t* s1, const wchar_t* s2);
730b57cec5SDimitry Andric int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n);
740b57cec5SDimitry Andric size_t wcsxfrm(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
750b57cec5SDimitry Andric const wchar_t* wcschr(const wchar_t* s, wchar_t c);
760b57cec5SDimitry Andric       wchar_t* wcschr(      wchar_t* s, wchar_t c);
770b57cec5SDimitry Andric size_t wcscspn(const wchar_t* s1, const wchar_t* s2);
780b57cec5SDimitry Andric size_t wcslen(const wchar_t* s);
790b57cec5SDimitry Andric const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2);
800b57cec5SDimitry Andric       wchar_t* wcspbrk(      wchar_t* s1, const wchar_t* s2);
810b57cec5SDimitry Andric const wchar_t* wcsrchr(const wchar_t* s, wchar_t c);
820b57cec5SDimitry Andric       wchar_t* wcsrchr(      wchar_t* s, wchar_t c);
830b57cec5SDimitry Andric size_t wcsspn(const wchar_t* s1, const wchar_t* s2);
840b57cec5SDimitry Andric const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2);
850b57cec5SDimitry Andric       wchar_t* wcsstr(      wchar_t* s1, const wchar_t* s2);
860b57cec5SDimitry Andric wchar_t* wcstok(wchar_t* restrict s1, const wchar_t* restrict s2, wchar_t** restrict ptr);
870b57cec5SDimitry Andric const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n);
880b57cec5SDimitry Andric       wchar_t* wmemchr(      wchar_t* s, wchar_t c, size_t n);
890b57cec5SDimitry Andric int wmemcmp(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
900b57cec5SDimitry Andric wchar_t* wmemcpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
910b57cec5SDimitry Andric wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n);
920b57cec5SDimitry Andric wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n);
930b57cec5SDimitry Andric size_t wcsftime(wchar_t* restrict s, size_t maxsize, const wchar_t* restrict format,
940b57cec5SDimitry Andric                 const tm* restrict timeptr);
950b57cec5SDimitry Andric wint_t btowc(int c);
960b57cec5SDimitry Andric int wctob(wint_t c);
970b57cec5SDimitry Andric int mbsinit(const mbstate_t* ps);
980b57cec5SDimitry Andric size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps);
990b57cec5SDimitry Andric size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, mbstate_t* restrict ps);
1000b57cec5SDimitry Andric size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps);
1010b57cec5SDimitry Andric size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src, size_t len,
1020b57cec5SDimitry Andric                  mbstate_t* restrict ps);
1030b57cec5SDimitry Andric size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
1040b57cec5SDimitry Andric                  mbstate_t* restrict ps);
1050b57cec5SDimitry Andric 
1060b57cec5SDimitry Andric */
1070b57cec5SDimitry Andric 
1080b57cec5SDimitry Andric #  include <__config>
1095ffd83dbSDimitry Andric #  include <stddef.h>
1100b57cec5SDimitry Andric 
111349cc55cSDimitry Andric #  if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
112cb14a3feSDimitry Andric #    error                                                                                                             \
113cb14a3feSDimitry Andric         "The <wchar.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
114349cc55cSDimitry Andric #  endif
115349cc55cSDimitry Andric 
1160b57cec5SDimitry Andric #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1170b57cec5SDimitry Andric #    pragma GCC system_header
1180b57cec5SDimitry Andric #  endif
1190b57cec5SDimitry Andric 
12006c3fb27SDimitry Andric // We define this here to support older versions of glibc <wchar.h> that do
12106c3fb27SDimitry Andric // not define this for clang.
1220b57cec5SDimitry Andric #  ifdef __cplusplus
1230b57cec5SDimitry Andric #    define __CORRECT_ISO_CPP_WCHAR_H_PROTO
1240b57cec5SDimitry Andric #  endif
1250b57cec5SDimitry Andric 
126bdd1243dSDimitry Andric #  if __has_include_next(<wchar.h>)
1270b57cec5SDimitry Andric #    include_next <wchar.h>
12806c3fb27SDimitry Andric #  else
12906c3fb27SDimitry Andric #    include <__mbstate_t.h> // make sure we have mbstate_t regardless of the existence of <wchar.h>
130bdd1243dSDimitry Andric #  endif
1310b57cec5SDimitry Andric 
1320b57cec5SDimitry Andric // Determine whether we have const-correct overloads for wcschr and friends.
1330b57cec5SDimitry Andric #  if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
1340b57cec5SDimitry Andric #    define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
1350b57cec5SDimitry Andric #  elif defined(__GLIBC_PREREQ)
1360b57cec5SDimitry Andric #    if __GLIBC_PREREQ(2, 10)
1370b57cec5SDimitry Andric #      define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
1380b57cec5SDimitry Andric #    endif
1390b57cec5SDimitry Andric #  elif defined(_LIBCPP_MSVCRT)
1400b57cec5SDimitry Andric #    if defined(_CRT_CONST_CORRECT_OVERLOADS)
1410b57cec5SDimitry Andric #      define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
1420b57cec5SDimitry Andric #    endif
1430b57cec5SDimitry Andric #  endif
1440b57cec5SDimitry Andric 
1450b57cec5SDimitry Andric #  if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
1460b57cec5SDimitry Andric extern "C++" {
__libcpp_wcschr(const wchar_t * __s,wchar_t __c)147cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {
148cb14a3feSDimitry Andric   return (wchar_t*)wcschr(__s, __c);
149cb14a3feSDimitry Andric }
wcschr(const wchar_t * __s,wchar_t __c)150cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {
151cb14a3feSDimitry Andric   return __libcpp_wcschr(__s, __c);
152cb14a3feSDimitry Andric }
wcschr(wchar_t * __s,wchar_t __c)153cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcschr(wchar_t* __s, wchar_t __c) {
154cb14a3feSDimitry Andric   return __libcpp_wcschr(__s, __c);
155cb14a3feSDimitry Andric }
1560b57cec5SDimitry Andric 
__libcpp_wcspbrk(const wchar_t * __s1,const wchar_t * __s2)157cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {
158cb14a3feSDimitry Andric   return (wchar_t*)wcspbrk(__s1, __s2);
159cb14a3feSDimitry Andric }
160cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
wcspbrk(const wchar_t * __s1,const wchar_t * __s2)161cb14a3feSDimitry Andric wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {
162cb14a3feSDimitry Andric   return __libcpp_wcspbrk(__s1, __s2);
163cb14a3feSDimitry Andric }
wcspbrk(wchar_t * __s1,const wchar_t * __s2)164cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcspbrk(wchar_t* __s1, const wchar_t* __s2) {
165cb14a3feSDimitry Andric   return __libcpp_wcspbrk(__s1, __s2);
166cb14a3feSDimitry Andric }
1670b57cec5SDimitry Andric 
__libcpp_wcsrchr(const wchar_t * __s,wchar_t __c)168cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {
169cb14a3feSDimitry Andric   return (wchar_t*)wcsrchr(__s, __c);
170cb14a3feSDimitry Andric }
wcsrchr(const wchar_t * __s,wchar_t __c)171cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {
172cb14a3feSDimitry Andric   return __libcpp_wcsrchr(__s, __c);
173cb14a3feSDimitry Andric }
wcsrchr(wchar_t * __s,wchar_t __c)174cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcsrchr(wchar_t* __s, wchar_t __c) {
175cb14a3feSDimitry Andric   return __libcpp_wcsrchr(__s, __c);
176cb14a3feSDimitry Andric }
1770b57cec5SDimitry Andric 
__libcpp_wcsstr(const wchar_t * __s1,const wchar_t * __s2)178cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {
179cb14a3feSDimitry Andric   return (wchar_t*)wcsstr(__s1, __s2);
180cb14a3feSDimitry Andric }
181cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
wcsstr(const wchar_t * __s1,const wchar_t * __s2)182cb14a3feSDimitry Andric wcsstr(const wchar_t* __s1, const wchar_t* __s2) {
183cb14a3feSDimitry Andric   return __libcpp_wcsstr(__s1, __s2);
184cb14a3feSDimitry Andric }
wcsstr(wchar_t * __s1,const wchar_t * __s2)185cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcsstr(wchar_t* __s1, const wchar_t* __s2) {
186cb14a3feSDimitry Andric   return __libcpp_wcsstr(__s1, __s2);
187cb14a3feSDimitry Andric }
1880b57cec5SDimitry Andric 
__libcpp_wmemchr(const wchar_t * __s,wchar_t __c,size_t __n)189cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {
190cb14a3feSDimitry Andric   return (wchar_t*)wmemchr(__s, __c, __n);
191cb14a3feSDimitry Andric }
192cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
wmemchr(const wchar_t * __s,wchar_t __c,size_t __n)193cb14a3feSDimitry Andric wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {
194cb14a3feSDimitry Andric   return __libcpp_wmemchr(__s, __c, __n);
195cb14a3feSDimitry Andric }
wmemchr(wchar_t * __s,wchar_t __c,size_t __n)196cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wmemchr(wchar_t* __s, wchar_t __c, size_t __n) {
197cb14a3feSDimitry Andric   return __libcpp_wmemchr(__s, __c, __n);
198cb14a3feSDimitry Andric }
1990b57cec5SDimitry Andric }
2000b57cec5SDimitry Andric #  endif
2010b57cec5SDimitry Andric 
202349cc55cSDimitry Andric #  if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
2030b57cec5SDimitry Andric extern "C" {
204cb14a3feSDimitry Andric size_t mbsnrtowcs(
205cb14a3feSDimitry Andric     wchar_t* __restrict __dst, const char** __restrict __src, size_t __nmc, size_t __len, mbstate_t* __restrict __ps);
206cb14a3feSDimitry Andric size_t wcsnrtombs(
207cb14a3feSDimitry Andric     char* __restrict __dst, const wchar_t** __restrict __src, size_t __nwc, size_t __len, mbstate_t* __restrict __ps);
208349cc55cSDimitry Andric } // extern "C"
209349cc55cSDimitry Andric #  endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
2100b57cec5SDimitry Andric 
2110b57cec5SDimitry Andric #endif // _LIBCPP_WCHAR_H
212