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_SUPPORT_BSD_LIKE_H |
| 10 | #define _LIBCPP___LOCALE_DIR_SUPPORT_BSD_LIKE_H |
| 11 | |
| 12 | #include <__config> |
| 13 | #include <__cstddef/size_t.h> |
| 14 | #include <__std_mbstate_t.h> |
| 15 | #include <__utility/forward.h> |
| 16 | #include <clocale> // std::lconv |
| 17 | #include <ctype.h> |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | #include <time.h> |
| 22 | #if _LIBCPP_HAS_WIDE_CHARACTERS |
| 23 | # include <wchar.h> |
| 24 | # include <wctype.h> |
| 25 | #endif |
| 26 | |
| 27 | #include <xlocale.h> |
| 28 | |
| 29 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 30 | # pragma GCC system_header |
| 31 | #endif |
| 32 | |
| 33 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 34 | namespace __locale { |
| 35 | |
| 36 | // |
| 37 | // Locale management |
| 38 | // |
| 39 | #define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK |
| 40 | #define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK |
| 41 | #define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK |
| 42 | #define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK |
| 43 | #define _LIBCPP_TIME_MASK LC_TIME_MASK |
| 44 | #define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK |
| 45 | #define _LIBCPP_ALL_MASK LC_ALL_MASK |
| 46 | #define _LIBCPP_LC_ALL LC_ALL |
| 47 | |
| 48 | using __locale_t _LIBCPP_NODEBUG = ::locale_t; |
| 49 | #if defined(_LIBCPP_BUILDING_LIBRARY) |
| 50 | using __lconv_t _LIBCPP_NODEBUG = std::lconv; |
| 51 | |
| 52 | inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __locale, __locale_t __base) { |
| 53 | return ::newlocale(__category_mask, __locale, __base); |
| 54 | } |
| 55 | |
| 56 | inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); } |
| 57 | |
| 58 | inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) { |
| 59 | return ::setlocale(__category, __locale); |
| 60 | } |
| 61 | |
| 62 | inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return ::localeconv_l(__loc); } |
| 63 | #endif // _LIBCPP_BUILDING_LIBRARY |
| 64 | |
| 65 | // |
| 66 | // Strtonum functions |
| 67 | // |
| 68 | inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) { |
| 69 | return ::strtof_l(__nptr, __endptr, __loc); |
| 70 | } |
| 71 | |
| 72 | inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) { |
| 73 | return ::strtod_l(__nptr, __endptr, __loc); |
| 74 | } |
| 75 | |
| 76 | inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) { |
| 77 | return ::strtold_l(__nptr, __endptr, __loc); |
| 78 | } |
| 79 | |
| 80 | inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { |
| 81 | return ::strtoll_l(__nptr, __endptr, __base, __loc); |
| 82 | } |
| 83 | |
| 84 | inline _LIBCPP_HIDE_FROM_ABI unsigned long long |
| 85 | __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { |
| 86 | return ::strtoull_l(__nptr, __endptr, __base, __loc); |
| 87 | } |
| 88 | |
| 89 | // |
| 90 | // Character manipulation functions |
| 91 | // |
| 92 | #if defined(_LIBCPP_BUILDING_LIBRARY) |
| 93 | inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return ::islower_l(__c, __loc); } |
| 94 | |
| 95 | inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return ::isupper_l(__c, __loc); } |
| 96 | #endif |
| 97 | |
| 98 | inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return ::isdigit_l(__c, __loc); } |
| 99 | |
| 100 | inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return ::isxdigit_l(__c, __loc); } |
| 101 | |
| 102 | #if defined(_LIBCPP_BUILDING_LIBRARY) |
| 103 | inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return ::toupper_l(__c, __loc); } |
| 104 | |
| 105 | inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t __loc) { return ::tolower_l(__c, __loc); } |
| 106 | |
| 107 | inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) { |
| 108 | return ::strcoll_l(__s1, __s2, __loc); |
| 109 | } |
| 110 | |
| 111 | inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) { |
| 112 | return ::strxfrm_l(__dest, __src, __n, __loc); |
| 113 | } |
| 114 | |
| 115 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 116 | inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) { |
| 117 | return ::iswctype_l(__c, __type, __loc); |
| 118 | } |
| 119 | |
| 120 | inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t __loc) { return ::iswspace_l(__c, __loc); } |
| 121 | |
| 122 | inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t __loc) { return ::iswprint_l(__c, __loc); } |
| 123 | |
| 124 | inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t __loc) { return ::iswcntrl_l(__c, __loc); } |
| 125 | |
| 126 | inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t __loc) { return ::iswupper_l(__c, __loc); } |
| 127 | |
| 128 | inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t __loc) { return ::iswlower_l(__c, __loc); } |
| 129 | |
| 130 | inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t __loc) { return ::iswalpha_l(__c, __loc); } |
| 131 | |
| 132 | inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t __loc) { return ::iswblank_l(__c, __loc); } |
| 133 | |
| 134 | inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t __loc) { return ::iswdigit_l(__c, __loc); } |
| 135 | |
| 136 | inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t __loc) { return ::iswpunct_l(__c, __loc); } |
| 137 | |
| 138 | inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t __loc) { return ::iswxdigit_l(__c, __loc); } |
| 139 | |
| 140 | inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t __loc) { return ::towupper_l(__c, __loc); } |
| 141 | |
| 142 | inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t __loc) { return ::towlower_l(__c, __loc); } |
| 143 | |
| 144 | inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) { |
| 145 | return ::wcscoll_l(__ws1, __ws2, __loc); |
| 146 | } |
| 147 | |
| 148 | inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) { |
| 149 | return ::wcsxfrm_l(__dest, __src, __n, __loc); |
| 150 | } |
| 151 | # endif // _LIBCPP_HAS_WIDE_CHARACTERS |
| 152 | |
| 153 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 154 | __strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) { |
| 155 | return ::strftime_l(__s, __max, __format, __tm, __loc); |
| 156 | } |
| 157 | |
| 158 | // |
| 159 | // Other functions |
| 160 | // |
| 161 | inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) { return MB_CUR_MAX_L(__loc); } |
| 162 | |
| 163 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 164 | inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __c, __locale_t __loc) { return ::btowc_l(__c, __loc); } |
| 165 | |
| 166 | inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __c, __locale_t __loc) { return ::wctob_l(__c, __loc); } |
| 167 | |
| 168 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 169 | __wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) { |
| 170 | return ::wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __loc); // wcsnrtombs is a POSIX extension |
| 171 | } |
| 172 | |
| 173 | inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __wc, mbstate_t* __ps, __locale_t __loc) { |
| 174 | return ::wcrtomb_l(__s, __wc, __ps, __loc); |
| 175 | } |
| 176 | |
| 177 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 178 | __mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) { |
| 179 | return ::mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __loc); // mbsnrtowcs is a POSIX extension |
| 180 | } |
| 181 | |
| 182 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 183 | __mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { |
| 184 | return ::mbrtowc_l(__pwc, __s, __n, __ps, __loc); |
| 185 | } |
| 186 | |
| 187 | inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) { |
| 188 | return ::mbtowc_l(__pwc, __pmb, __max, __loc); |
| 189 | } |
| 190 | |
| 191 | inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { |
| 192 | return ::mbrlen_l(__s, __n, __ps, __loc); |
| 193 | } |
| 194 | |
| 195 | inline _LIBCPP_HIDE_FROM_ABI size_t |
| 196 | __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) { |
| 197 | return ::mbsrtowcs_l(__dest, __src, __len, __ps, __loc); |
| 198 | } |
| 199 | # endif // _LIBCPP_HAS_WIDE_CHARACTERS |
| 200 | #endif // _LIBCPP_BUILDING_LIBRARY |
| 201 | |
| 202 | _LIBCPP_DIAGNOSTIC_PUSH |
| 203 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") |
| 204 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates |
| 205 | #ifdef _LIBCPP_COMPILER_CLANG_BASED |
| 206 | # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__) |
| 207 | #else |
| 208 | # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */ |
| 209 | #endif |
| 210 | |
| 211 | template <class... _Args> |
| 212 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf( |
| 213 | char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) { |
| 214 | return ::snprintf_l(__s, __n, __loc, __format, std::forward<_Args>(__args)...); |
| 215 | } |
| 216 | |
| 217 | template <class... _Args> |
| 218 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf( |
| 219 | char** __s, __locale_t __loc, const char* __format, _Args&&... __args) { |
| 220 | return ::asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...); // non-standard |
| 221 | } |
| 222 | |
| 223 | template <class... _Args> |
| 224 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf( |
| 225 | const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) { |
| 226 | return ::sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...); |
| 227 | } |
| 228 | _LIBCPP_DIAGNOSTIC_POP |
| 229 | #undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT |
| 230 | |
| 231 | } // namespace __locale |
| 232 | _LIBCPP_END_NAMESPACE_STD |
| 233 | |
| 234 | #endif // _LIBCPP___LOCALE_DIR_SUPPORT_BSD_LIKE_H |
| 235 |
Warning: This file is not a C or C++ file. It does not have highlighting.
