Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | eb8650a | 2021-11-17 21:25:01 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Yi Kong | 3f65c8f | 2022-11-22 11:11:42 | [diff] [blame] | 10 | #if defined(__need_wint_t) || defined(__need_mbstate_t) |
| 11 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 12 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 13 | # pragma GCC system_header |
| 14 | # endif |
Yi Kong | 3f65c8f | 2022-11-22 11:11:42 | [diff] [blame] | 15 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 16 | # include_next <wchar.h> |
Yi Kong | 3f65c8f | 2022-11-22 11:11:42 | [diff] [blame] | 17 | |
| 18 | #elif !defined(_LIBCPP_WCHAR_H) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 19 | # define _LIBCPP_WCHAR_H |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | wchar.h synopsis |
| 23 | |
| 24 | Macros: |
| 25 | |
| 26 | NULL |
| 27 | WCHAR_MAX |
| 28 | WCHAR_MIN |
| 29 | WEOF |
| 30 | |
| 31 | Types: |
| 32 | |
| 33 | mbstate_t |
| 34 | size_t |
| 35 | tm |
| 36 | wint_t |
| 37 | |
| 38 | int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...); |
| 39 | int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...); |
| 40 | int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, ...); |
| 41 | int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...); |
| 42 | int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); |
| 43 | int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); // C99 |
| 44 | int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, va_list arg); |
| 45 | int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, va_list arg); // C99 |
| 46 | int vwprintf(const wchar_t* restrict format, va_list arg); |
| 47 | int vwscanf(const wchar_t* restrict format, va_list arg); // C99 |
| 48 | int wprintf(const wchar_t* restrict format, ...); |
| 49 | int wscanf(const wchar_t* restrict format, ...); |
| 50 | wint_t fgetwc(FILE* stream); |
| 51 | wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream); |
| 52 | wint_t fputwc(wchar_t c, FILE* stream); |
| 53 | int fputws(const wchar_t* restrict s, FILE* restrict stream); |
| 54 | int fwide(FILE* stream, int mode); |
| 55 | wint_t getwc(FILE* stream); |
| 56 | wint_t getwchar(); |
| 57 | wint_t putwc(wchar_t c, FILE* stream); |
| 58 | wint_t putwchar(wchar_t c); |
| 59 | wint_t ungetwc(wint_t c, FILE* stream); |
| 60 | double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr); |
| 61 | float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99 |
| 62 | long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99 |
| 63 | long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); |
| 64 | long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99 |
| 65 | unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); |
| 66 | unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99 |
| 67 | wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2); |
| 68 | wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); |
| 69 | wchar_t* wcscat(wchar_t* restrict s1, const wchar_t* restrict s2); |
| 70 | wchar_t* wcsncat(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); |
| 71 | int wcscmp(const wchar_t* s1, const wchar_t* s2); |
| 72 | int wcscoll(const wchar_t* s1, const wchar_t* s2); |
| 73 | int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n); |
| 74 | size_t wcsxfrm(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); |
| 75 | const wchar_t* wcschr(const wchar_t* s, wchar_t c); |
| 76 | wchar_t* wcschr( wchar_t* s, wchar_t c); |
| 77 | size_t wcscspn(const wchar_t* s1, const wchar_t* s2); |
| 78 | size_t wcslen(const wchar_t* s); |
| 79 | const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2); |
| 80 | wchar_t* wcspbrk( wchar_t* s1, const wchar_t* s2); |
| 81 | const wchar_t* wcsrchr(const wchar_t* s, wchar_t c); |
| 82 | wchar_t* wcsrchr( wchar_t* s, wchar_t c); |
| 83 | size_t wcsspn(const wchar_t* s1, const wchar_t* s2); |
| 84 | const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2); |
| 85 | wchar_t* wcsstr( wchar_t* s1, const wchar_t* s2); |
| 86 | wchar_t* wcstok(wchar_t* restrict s1, const wchar_t* restrict s2, wchar_t** restrict ptr); |
| 87 | const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n); |
| 88 | wchar_t* wmemchr( wchar_t* s, wchar_t c, size_t n); |
| 89 | int wmemcmp(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); |
| 90 | wchar_t* wmemcpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n); |
| 91 | wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n); |
| 92 | wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n); |
| 93 | size_t wcsftime(wchar_t* restrict s, size_t maxsize, const wchar_t* restrict format, |
| 94 | const tm* restrict timeptr); |
| 95 | wint_t btowc(int c); |
| 96 | int wctob(wint_t c); |
| 97 | int mbsinit(const mbstate_t* ps); |
| 98 | size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps); |
| 99 | size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, mbstate_t* restrict ps); |
| 100 | size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps); |
| 101 | size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src, size_t len, |
| 102 | mbstate_t* restrict ps); |
| 103 | size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, |
| 104 | mbstate_t* restrict ps); |
| 105 | |
| 106 | */ |
| 107 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 108 | # include <__config> |
| 109 | # include <stddef.h> |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 110 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 111 | # if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) |
| 112 | # error \ |
| 113 | "The <wchar.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled" |
| 114 | # endif |
Louis Dionne | f4c1258 | 2021-08-23 19:32:36 | [diff] [blame] | 115 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 116 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 117 | # pragma GCC system_header |
| 118 | # endif |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 119 | |
Jordan Rupprecht | 0ec57bf | 2023-05-10 22:43:37 | [diff] [blame] | 120 | // We define this here to support older versions of glibc <wchar.h> that do |
| 121 | // not define this for clang. |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 122 | # ifdef __cplusplus |
| 123 | # define __CORRECT_ISO_CPP_WCHAR_H_PROTO |
| 124 | # endif |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 125 | |
Louis Dionne | 5d87f60 | 2022-11-15 22:08:01 | [diff] [blame] | 126 | # if __has_include_next(<wchar.h>) |
| 127 | # include_next <wchar.h> |
Ian Anderson | a595b93 | 2023-04-17 16:38:38 | [diff] [blame] | 128 | # else |
| 129 | # include <__mbstate_t.h> // make sure we have mbstate_t regardless of the existence of <wchar.h> |
Louis Dionne | 5d87f60 | 2022-11-15 22:08:01 | [diff] [blame] | 130 | # endif |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 131 | |
Richard Smith | 5fd17ab | 2016-02-10 00:59:02 | [diff] [blame] | 132 | // Determine whether we have const-correct overloads for wcschr and friends. |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 133 | # if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_) |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 134 | # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 135 | # elif defined(__GLIBC_PREREQ) |
| 136 | # if __GLIBC_PREREQ(2, 10) |
| 137 | # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 |
| 138 | # endif |
| 139 | # elif defined(_LIBCPP_MSVCRT) |
| 140 | # if defined(_CRT_CONST_CORRECT_OVERLOADS) |
| 141 | # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 |
| 142 | # endif |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 143 | # endif |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 144 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 145 | # if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD) |
Richard Smith | 5fd17ab | 2016-02-10 00:59:02 | [diff] [blame] | 146 | extern "C++" { |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 147 | inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) { |
| 148 | return (wchar_t*)wcschr(__s, __c); |
Richard Smith | 5fd17ab | 2016-02-10 00:59:02 | [diff] [blame] | 149 | } |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 150 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) { |
| 151 | return __libcpp_wcschr(__s, __c); |
| 152 | } |
| 153 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcschr(wchar_t* __s, wchar_t __c) { |
| 154 | return __libcpp_wcschr(__s, __c); |
| 155 | } |
Richard Smith | 5fd17ab | 2016-02-10 00:59:02 | [diff] [blame] | 156 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 157 | inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) { |
| 158 | return (wchar_t*)wcspbrk(__s1, __s2); |
| 159 | } |
| 160 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* |
| 161 | wcspbrk(const wchar_t* __s1, const wchar_t* __s2) { |
| 162 | return __libcpp_wcspbrk(__s1, __s2); |
| 163 | } |
| 164 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcspbrk(wchar_t* __s1, const wchar_t* __s2) { |
| 165 | return __libcpp_wcspbrk(__s1, __s2); |
| 166 | } |
| 167 | |
| 168 | inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) { |
| 169 | return (wchar_t*)wcsrchr(__s, __c); |
| 170 | } |
| 171 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) { |
| 172 | return __libcpp_wcsrchr(__s, __c); |
| 173 | } |
| 174 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcsrchr(wchar_t* __s, wchar_t __c) { |
| 175 | return __libcpp_wcsrchr(__s, __c); |
| 176 | } |
| 177 | |
| 178 | inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) { |
| 179 | return (wchar_t*)wcsstr(__s1, __s2); |
| 180 | } |
| 181 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* |
| 182 | wcsstr(const wchar_t* __s1, const wchar_t* __s2) { |
| 183 | return __libcpp_wcsstr(__s1, __s2); |
| 184 | } |
| 185 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcsstr(wchar_t* __s1, const wchar_t* __s2) { |
| 186 | return __libcpp_wcsstr(__s1, __s2); |
| 187 | } |
| 188 | |
| 189 | inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) { |
| 190 | return (wchar_t*)wmemchr(__s, __c, __n); |
| 191 | } |
| 192 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* |
| 193 | wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) { |
| 194 | return __libcpp_wmemchr(__s, __c, __n); |
| 195 | } |
| 196 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wmemchr(wchar_t* __s, wchar_t __c, size_t __n) { |
| 197 | return __libcpp_wmemchr(__s, __c, __n); |
| 198 | } |
| 199 | } |
| 200 | # endif |
| 201 | |
| 202 | # if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__)) |
Eric Fiselier | 5d50aa3 | 2017-05-10 20:57:45 | [diff] [blame] | 203 | extern "C" { |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 204 | size_t mbsnrtowcs( |
| 205 | wchar_t* __restrict __dst, const char** __restrict __src, size_t __nmc, size_t __len, mbstate_t* __restrict __ps); |
| 206 | size_t wcsnrtombs( |
| 207 | char* __restrict __dst, const wchar_t** __restrict __src, size_t __nwc, size_t __len, mbstate_t* __restrict __ps); |
Louis Dionne | 4e1a23e | 2023-08-11 17:24:51 | [diff] [blame] | 208 | } // extern "C" |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 209 | # endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__) |
Richard Smith | 0ecae01 | 2015-10-10 01:39:51 | [diff] [blame] | 210 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 211 | #endif // _LIBCPP_WCHAR_H |