Warning: This file is not a C or C++ file. It does not have highlighting.
| 1 | //===-----------------------------------------------------------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H |
| 10 | #define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H |
| 11 | |
| 12 | #include <__config> |
| 13 | |
| 14 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 15 | # pragma GCC system_header |
| 16 | #endif |
| 17 | |
| 18 | // The platform-specific headers have to provide the following interface. |
| 19 | // |
| 20 | // These functions are equivalent to their C counterparts, except that __locale::__locale_t |
| 21 | // is used instead of the current global locale. |
| 22 | // |
| 23 | // Variadic functions may be implemented as templates with a parameter pack instead |
| 24 | // of C-style variadic functions. |
| 25 | // |
| 26 | // Most of these functions are only required when building the library. Functions that are also |
| 27 | // required when merely using the headers are marked as such below. |
| 28 | // |
| 29 | // TODO: __localeconv shouldn't take a reference, but the Windows implementation doesn't allow copying __locale_t |
| 30 | // TODO: Eliminate the need for any of these functions from the headers. |
| 31 | // |
| 32 | // Locale management |
| 33 | // ----------------- |
| 34 | // namespace __locale { |
| 35 | // using __locale_t = implementation-defined; // required by the headers |
| 36 | // using __lconv_t = implementation-defined; |
| 37 | // __locale_t __newlocale(int, const char*, __locale_t); |
| 38 | // void __freelocale(__locale_t); |
| 39 | // char* __setlocale(int, const char*); |
| 40 | // __lconv_t* __localeconv(__locale_t&); |
| 41 | // } |
| 42 | // |
| 43 | // // required by the headers |
| 44 | // #define _LIBCPP_COLLATE_MASK /* implementation-defined */ |
| 45 | // #define _LIBCPP_CTYPE_MASK /* implementation-defined */ |
| 46 | // #define _LIBCPP_MONETARY_MASK /* implementation-defined */ |
| 47 | // #define _LIBCPP_NUMERIC_MASK /* implementation-defined */ |
| 48 | // #define _LIBCPP_TIME_MASK /* implementation-defined */ |
| 49 | // #define _LIBCPP_MESSAGES_MASK /* implementation-defined */ |
| 50 | // #define _LIBCPP_ALL_MASK /* implementation-defined */ |
| 51 | // #define _LIBCPP_LC_ALL /* implementation-defined */ |
| 52 | // |
| 53 | // Strtonum functions |
| 54 | // ------------------ |
| 55 | // namespace __locale { |
| 56 | // // required by the headers |
| 57 | // float __strtof(const char*, char**, __locale_t); |
| 58 | // double __strtod(const char*, char**, __locale_t); |
| 59 | // long double __strtold(const char*, char**, __locale_t); |
| 60 | // long long __strtoll(const char*, char**, __locale_t); |
| 61 | // unsigned long long __strtoull(const char*, char**, __locale_t); |
| 62 | // } |
| 63 | // |
| 64 | // Character manipulation functions |
| 65 | // -------------------------------- |
| 66 | // namespace __locale { |
| 67 | // int __islower(int, __locale_t); |
| 68 | // int __isupper(int, __locale_t); |
| 69 | // int __isdigit(int, __locale_t); // required by the headers |
| 70 | // int __isxdigit(int, __locale_t); // required by the headers |
| 71 | // int __toupper(int, __locale_t); |
| 72 | // int __tolower(int, __locale_t); |
| 73 | // int __strcoll(const char*, const char*, __locale_t); |
| 74 | // size_t __strxfrm(char*, const char*, size_t, __locale_t); |
| 75 | // |
| 76 | // int __iswctype(wint_t, wctype_t, __locale_t); |
| 77 | // int __iswspace(wint_t, __locale_t); |
| 78 | // int __iswprint(wint_t, __locale_t); |
| 79 | // int __iswcntrl(wint_t, __locale_t); |
| 80 | // int __iswupper(wint_t, __locale_t); |
| 81 | // int __iswlower(wint_t, __locale_t); |
| 82 | // int __iswalpha(wint_t, __locale_t); |
| 83 | // int __iswblank(wint_t, __locale_t); |
| 84 | // int __iswdigit(wint_t, __locale_t); |
| 85 | // int __iswpunct(wint_t, __locale_t); |
| 86 | // int __iswxdigit(wint_t, __locale_t); |
| 87 | // wint_t __towupper(wint_t, __locale_t); |
| 88 | // wint_t __towlower(wint_t, __locale_t); |
| 89 | // int __wcscoll(const wchar_t*, const wchar_t*, __locale_t); |
| 90 | // size_t __wcsxfrm(wchar_t*, const wchar_t*, size_t, __locale_t); |
| 91 | // |
| 92 | // size_t __strftime(char*, size_t, const char*, const tm*, __locale_t); |
| 93 | // } |
| 94 | // |
| 95 | // Other functions |
| 96 | // --------------- |
| 97 | // namespace __locale { |
| 98 | // implementation-defined __mb_len_max(__locale_t); |
| 99 | // wint_t __btowc(int, __locale_t); |
| 100 | // int __wctob(wint_t, __locale_t); |
| 101 | // size_t __wcsnrtombs(char*, const wchar_t**, size_t, size_t, mbstate_t*, __locale_t); |
| 102 | // size_t __wcrtomb(char*, wchar_t, mbstate_t*, __locale_t); |
| 103 | // size_t __mbsnrtowcs(wchar_t*, const char**, size_t, size_t, mbstate_t*, __locale_t); |
| 104 | // size_t __mbrtowc(wchar_t*, const char*, size_t, mbstate_t*, __locale_t); |
| 105 | // int __mbtowc(wchar_t*, const char*, size_t, __locale_t); |
| 106 | // size_t __mbrlen(const char*, size_t, mbstate_t*, __locale_t); |
| 107 | // size_t __mbsrtowcs(wchar_t*, const char**, size_t, mbstate_t*, __locale_t); |
| 108 | // |
| 109 | // int __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers |
| 110 | // int __asprintf(char**, __locale_t, const char*, ...); // required by the headers |
| 111 | // int __sscanf(const char*, __locale_t, const char*, ...); // required by the headers |
| 112 | // } |
| 113 | |
| 114 | #if _LIBCPP_HAS_LOCALIZATION |
| 115 | |
| 116 | # if defined(__APPLE__) |
| 117 | # include <__locale_dir/support/apple.h> |
| 118 | # elif defined(__FreeBSD__) |
| 119 | # include <__locale_dir/support/freebsd.h> |
| 120 | # elif defined(_LIBCPP_MSVCRT_LIKE) |
| 121 | # include <__locale_dir/support/windows.h> |
| 122 | # elif defined(__Fuchsia__) |
| 123 | # include <__locale_dir/support/fuchsia.h> |
| 124 | # elif defined(__linux__) |
| 125 | # include <__locale_dir/support/linux.h> |
| 126 | # else |
| 127 | |
| 128 | // TODO: This is a temporary definition to bridge between the old way we defined the locale base API |
| 129 | // (by providing global non-reserved names) and the new API. As we move individual platforms |
| 130 | // towards the new way of defining the locale base API, this should disappear since each platform |
| 131 | // will define those directly. |
| 132 | # if defined(_AIX) || defined(__MVS__) |
| 133 | # include <__locale_dir/locale_base_api/ibm.h> |
| 134 | # elif defined(__ANDROID__) |
| 135 | # include <__locale_dir/locale_base_api/android.h> |
| 136 | # elif defined(__OpenBSD__) |
| 137 | # include <__locale_dir/locale_base_api/openbsd.h> |
| 138 | # elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC |
| 139 | # include <__locale_dir/locale_base_api/musl.h> |
| 140 | # endif |
| 141 | |
| 142 | # include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h> |
| 143 | |
| 144 | # include <__cstddef/size_t.h> |
| 145 | # include <__utility/forward.h> |
| 146 | # include <ctype.h> |
| 147 | # include <string.h> |
| 148 | # include <time.h> |
| 149 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 150 | # include <wctype.h> |
| 151 | # endif |
| 152 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 153 | namespace __locale { |
| 154 | // |
| 155 | // Locale management |
| 156 | // |
| 157 | # define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK |
| 158 | # define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK |
| 159 | # define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK |
| 160 | # define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK |
| 161 | # define _LIBCPP_TIME_MASK LC_TIME_MASK |
| 162 | # define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK |
| 163 | # define _LIBCPP_ALL_MASK LC_ALL_MASK |
| 164 | # define _LIBCPP_LC_ALL LC_ALL |
| 165 | |
| 166 | using __locale_t _LIBCPP_NODEBUG = locale_t; |
| 167 | |
| 168 | # if defined(_LIBCPP_BUILDING_LIBRARY) |
| 169 | using __lconv_t _LIBCPP_NODEBUG = lconv; |
| 170 | |
| 171 | inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) { |
| 172 | return newlocale(__category_mask, __name, __loc); |
| 173 | } |
| 174 | |
| 175 | inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) { |
| 176 | return ::setlocale(__category, __locale); |
| 177 | } |
| 178 | |
| 179 | inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { freelocale(__loc); } |
| 180 | |
| 181 | inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return __libcpp_localeconv_l(__loc); } |
| 182 | # endif // _LIBCPP_BUILDING_LIBRARY |
| 183 | |
| 184 | // |
| 185 | // Strtonum functions |
| 186 | // |
| 187 | inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) { |
| 188 | return strtof_l(__nptr, __endptr, __loc); |
| 189 | } |
| 190 | |
| 191 | inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) { |
| 192 | return strtod_l(__nptr, __endptr, __loc); |
| 193 | } |
| 194 | |
| 195 | inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) { |
| 196 | return strtold_l(__nptr, __endptr, __loc); |
| 197 | } |
| 198 | |
| 199 | inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { |
| 200 | return strtoll_l(__nptr, __endptr, __base, __loc); |
| 201 | } |
| 202 | |
| 203 | inline _LIBCPP_HIDE_FROM_ABI unsigned long long |
| 204 | __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { |
| 205 | return strtoull_l(__nptr, __endptr, __base, __loc); |
| 206 | } |
| 207 | |
| 208 | // |
| 209 | // Character manipulation functions |
| 210 | // |
| 211 | # if defined(_LIBCPP_BUILDING_LIBRARY) |
| 212 | inline _LIBCPP_HIDE_FROM_ABI int __islower(int __ch, __locale_t __loc) { return islower_l(__ch, __loc); } |
| 213 | inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __ch, __locale_t __loc) { return isupper_l(__ch, __loc); } |
| 214 | # endif |
| 215 | |
| 216 | inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __ch, __locale_t __loc) { return isdigit_l(__ch, __loc); } |
| 217 | inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __ch, __locale_t __loc) { return isxdigit_l(__ch, __loc); } |
| 218 | |
| 219 | # if defined(_LIBCPP_BUILDING_LIBRARY) |
| 220 | inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) { |
| 221 | return strcoll_l(__s1, __s2, __loc); |
| 222 | } |
| 223 | inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) { |
| 224 | return strxfrm_l(__dest, __src, __n, __loc); |
| 225 | } |
| 226 | inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __ch, __locale_t __loc) { return toupper_l(__ch, __loc); } |
| 227 | inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __ch, __locale_t __loc) { return tolower_l(__ch, __loc); } |
| 228 | |
| 229 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 230 | inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __s1, const wchar_t* __s2, __locale_t __loc) { |
| 231 | return wcscoll_l(__s1, __s2, __loc); |
| 232 | } |
| 233 | inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) { |
| 234 | return wcsxfrm_l(__dest, __src, __n, __loc); |
| 235 | } |
| 236 | inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __ch, wctype_t __type, __locale_t __loc) { |
| 237 | return iswctype_l(__ch, __type, __loc); |
| 238 | } |
| 239 | inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __ch, __locale_t __loc) { return iswspace_l(__ch, __loc); } |
| 240 | inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __ch, __locale_t __loc) { return iswprint_l(__ch, __loc); } |
| 241 | inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __ch, __locale_t __loc) { return iswcntrl_l(__ch, __loc); } |
| 242 | inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __ch, __locale_t __loc) { return iswupper_l(__ch, __loc); } |
| 243 | inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __ch, __locale_t __loc) { return iswlower_l(__ch, __loc); } |
| 244 | inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __ch, __locale_t __loc) { return iswalpha_l(__ch, __loc); } |
| 245 | inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __ch, __locale_t __loc) { return iswblank_l(__ch, __loc); } |
| 246 | inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __ch, __locale_t __loc) { return iswdigit_l(__ch, __loc); } |
| 247 | inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __ch, __locale_t __loc) { return iswpunct_l(__ch, __loc); } |
| 248 | inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __ch, __locale_t __loc) { return iswxdigit_l(__ch, __loc); } |
| 249 | inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __ch, __locale_t __loc) { return towupper_l(__ch, __loc); } |
| 250 | inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __ch, __locale_t __loc) { return towlower_l(__ch, __loc); } |
| 251 | # endif |
| 252 | |
| 253 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 254 | __strftime(char* __s, size_t __max, const char* __format, const tm* __tm, __locale_t __loc) { |
| 255 | return strftime_l(__s, __max, __format, __tm, __loc); |
| 256 | } |
| 257 | |
| 258 | // |
| 259 | // Other functions |
| 260 | // |
| 261 | inline _LIBCPP_HIDE_FROM_ABI decltype(__libcpp_mb_cur_max_l(__locale_t())) __mb_len_max(__locale_t __loc) { |
| 262 | return __libcpp_mb_cur_max_l(__loc); |
| 263 | } |
| 264 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 265 | inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) { return __libcpp_btowc_l(__ch, __loc); } |
| 266 | inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) { return __libcpp_wctob_l(__ch, __loc); } |
| 267 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 268 | __wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) { |
| 269 | return __libcpp_wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __loc); |
| 270 | } |
| 271 | inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) { |
| 272 | return __libcpp_wcrtomb_l(__s, __ch, __ps, __loc); |
| 273 | } |
| 274 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 275 | __mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) { |
| 276 | return __libcpp_mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __loc); |
| 277 | } |
| 278 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 279 | __mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { |
| 280 | return __libcpp_mbrtowc_l(__pwc, __s, __n, __ps, __loc); |
| 281 | } |
| 282 | inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) { |
| 283 | return __libcpp_mbtowc_l(__pwc, __pmb, __max, __loc); |
| 284 | } |
| 285 | inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { |
| 286 | return __libcpp_mbrlen_l(__s, __n, __ps, __loc); |
| 287 | } |
| 288 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 289 | __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) { |
| 290 | return __libcpp_mbsrtowcs_l(__dest, __src, __len, __ps, __loc); |
| 291 | } |
| 292 | # endif // _LIBCPP_HAS_WIDE_CHARACTERS |
| 293 | # endif // _LIBCPP_BUILDING_LIBRARY |
| 294 | |
| 295 | _LIBCPP_DIAGNOSTIC_PUSH |
| 296 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") |
| 297 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates |
| 298 | # ifdef _LIBCPP_COMPILER_CLANG_BASED |
| 299 | # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__) |
| 300 | # else |
| 301 | # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */ |
| 302 | # endif |
| 303 | |
| 304 | template <class... _Args> |
| 305 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf( |
| 306 | char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) { |
| 307 | return std::__libcpp_snprintf_l(__s, __n, __loc, __format, std::forward<_Args>(__args)...); |
| 308 | } |
| 309 | template <class... _Args> |
| 310 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf( |
| 311 | char** __s, __locale_t __loc, const char* __format, _Args&&... __args) { |
| 312 | return std::__libcpp_asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...); |
| 313 | } |
| 314 | template <class... _Args> |
| 315 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf( |
| 316 | const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) { |
| 317 | return std::__libcpp_sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...); |
| 318 | } |
| 319 | _LIBCPP_DIAGNOSTIC_POP |
| 320 | # undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT |
| 321 | |
| 322 | } // namespace __locale |
| 323 | _LIBCPP_END_NAMESPACE_STD |
| 324 | |
| 325 | # endif // Compatibility definition of locale base APIs |
| 326 | |
| 327 | #endif // _LIBCPP_HAS_LOCALIZATION |
| 328 | |
| 329 | #endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H |
| 330 |
Warning: This file is not a C or C++ file. It does not have highlighting.
