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) 112349cc55cSDimitry Andric # error "The <wchar.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled" 113349cc55cSDimitry Andric #endif 114349cc55cSDimitry Andric 1150b57cec5SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1160b57cec5SDimitry Andric # pragma GCC system_header 1170b57cec5SDimitry Andric #endif 1180b57cec5SDimitry Andric 119*06c3fb27SDimitry Andric // We define this here to support older versions of glibc <wchar.h> that do 120*06c3fb27SDimitry Andric // not define this for clang. 1210b57cec5SDimitry Andric #ifdef __cplusplus 1220b57cec5SDimitry Andric #define __CORRECT_ISO_CPP_WCHAR_H_PROTO 1230b57cec5SDimitry Andric #endif 1240b57cec5SDimitry Andric 125bdd1243dSDimitry Andric # if __has_include_next(<wchar.h>) 1260b57cec5SDimitry Andric # include_next <wchar.h> 127*06c3fb27SDimitry Andric # else 128*06c3fb27SDimitry Andric # include <__mbstate_t.h> // make sure we have mbstate_t regardless of the existence of <wchar.h> 129bdd1243dSDimitry Andric # endif 1300b57cec5SDimitry Andric 1310b57cec5SDimitry Andric // Determine whether we have const-correct overloads for wcschr and friends. 1320b57cec5SDimitry Andric #if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_) 1330b57cec5SDimitry Andric # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 1340b57cec5SDimitry Andric #elif defined(__GLIBC_PREREQ) 1350b57cec5SDimitry Andric # if __GLIBC_PREREQ(2, 10) 1360b57cec5SDimitry Andric # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 1370b57cec5SDimitry Andric # endif 1380b57cec5SDimitry Andric #elif defined(_LIBCPP_MSVCRT) 1390b57cec5SDimitry Andric # if defined(_CRT_CONST_CORRECT_OVERLOADS) 1400b57cec5SDimitry Andric # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 1410b57cec5SDimitry Andric # endif 1420b57cec5SDimitry Andric #endif 1430b57cec5SDimitry Andric 1440b57cec5SDimitry Andric #if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD) 1450b57cec5SDimitry Andric extern "C++" { 1460b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY 1470b57cec5SDimitry Andric wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcschr(__s, __c);} 1480b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1490b57cec5SDimitry Andric const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} 1500b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1510b57cec5SDimitry Andric wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY 1540b57cec5SDimitry Andric wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcspbrk(__s1, __s2);} 1550b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1560b57cec5SDimitry Andric const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);} 1570b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1580b57cec5SDimitry Andric wchar_t* wcspbrk( wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);} 1590b57cec5SDimitry Andric 1600b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY 1610b57cec5SDimitry Andric wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcsrchr(__s, __c);} 1620b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1630b57cec5SDimitry Andric const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);} 1640b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1650b57cec5SDimitry Andric wchar_t* wcsrchr( wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);} 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY 1680b57cec5SDimitry Andric wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} 1690b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1700b57cec5SDimitry Andric const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);} 1710b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1720b57cec5SDimitry Andric wchar_t* wcsstr( wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);} 1730b57cec5SDimitry Andric 1740b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY 1750b57cec5SDimitry Andric wchar_t* __libcpp_wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return (wchar_t*)wmemchr(__s, __c, __n);} 1760b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1770b57cec5SDimitry Andric const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);} 1780b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD 1790b57cec5SDimitry Andric wchar_t* wmemchr( wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);} 1800b57cec5SDimitry Andric } 1810b57cec5SDimitry Andric #endif 1820b57cec5SDimitry Andric 183349cc55cSDimitry Andric #if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__)) 1840b57cec5SDimitry Andric extern "C" { 185753f127fSDimitry Andric size_t mbsnrtowcs(wchar_t *__restrict __dst, const char **__restrict __src, 186753f127fSDimitry Andric size_t __nmc, size_t __len, mbstate_t *__restrict __ps); 187753f127fSDimitry Andric size_t wcsnrtombs(char *__restrict __dst, const wchar_t **__restrict __src, 188753f127fSDimitry Andric size_t __nwc, size_t __len, mbstate_t *__restrict __ps); 189349cc55cSDimitry Andric } // extern "C" 190349cc55cSDimitry Andric #endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__) 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andric #endif // _LIBCPP_WCHAR_H 193