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_FUCHSIA_H |
10 | #define _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H |
11 | |
12 | #include <__config> |
13 | #include <__utility/forward.h> |
14 | #include <clocale> // uselocale & friends |
15 | #include <cstdio> |
16 | #include <cstdlib> |
17 | #include <cwchar> |
18 | |
19 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
20 | # pragma GCC system_header |
21 | #endif |
22 | |
23 | _LIBCPP_BEGIN_NAMESPACE_STD |
24 | namespace __locale { |
25 | |
26 | struct __locale_guard { |
27 | _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {} |
28 | |
29 | _LIBCPP_HIDE_FROM_ABI ~__locale_guard() { |
30 | if (__old_loc_) |
31 | ::uselocale(__old_loc_); |
32 | } |
33 | |
34 | locale_t __old_loc_; |
35 | |
36 | __locale_guard(__locale_guard const&) = delete; |
37 | __locale_guard& operator=(__locale_guard const&) = delete; |
38 | }; |
39 | |
40 | // |
41 | // Locale management |
42 | // |
43 | #define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK |
44 | #define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK |
45 | #define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK |
46 | #define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK |
47 | #define _LIBCPP_TIME_MASK LC_TIME_MASK |
48 | #define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK |
49 | #define _LIBCPP_ALL_MASK LC_ALL_MASK |
50 | #define _LIBCPP_LC_ALL LC_ALL |
51 | |
52 | using __locale_t _LIBCPP_NODEBUG = locale_t; |
53 | |
54 | #if defined(_LIBCPP_BUILDING_LIBRARY) |
55 | using __lconv_t _LIBCPP_NODEBUG = std::lconv; |
56 | |
57 | inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) { |
58 | return ::newlocale(__category_mask, __name, __loc); |
59 | } |
60 | |
61 | inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); } |
62 | |
63 | inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) { |
64 | return ::setlocale(__category, __locale); |
65 | } |
66 | |
67 | inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { |
68 | __locale_guard __current(__loc); |
69 | return std::localeconv(); |
70 | } |
71 | |
72 | // |
73 | // Other functions |
74 | // |
75 | inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) { |
76 | __locale_guard __current(__loc); |
77 | return MB_CUR_MAX; |
78 | } |
79 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
80 | inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) { |
81 | __locale_guard __current(__loc); |
82 | return std::btowc(__ch); |
83 | } |
84 | inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) { |
85 | __locale_guard __current(__loc); |
86 | return std::wctob(__ch); |
87 | } |
88 | inline _LIBCPP_HIDE_FROM_ABI size_t |
89 | __wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) { |
90 | __locale_guard __current(__loc); |
91 | return ::wcsnrtombs(__dest, __src, __nwc, __len, __ps); // non-standard |
92 | } |
93 | inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) { |
94 | __locale_guard __current(__loc); |
95 | return std::wcrtomb(__s, __ch, __ps); |
96 | } |
97 | inline _LIBCPP_HIDE_FROM_ABI size_t |
98 | __mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) { |
99 | __locale_guard __current(__loc); |
100 | return ::mbsnrtowcs(__dest, __src, __nms, __len, __ps); // non-standard |
101 | } |
102 | inline _LIBCPP_HIDE_FROM_ABI size_t |
103 | __mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { |
104 | __locale_guard __current(__loc); |
105 | return std::mbrtowc(__pwc, __s, __n, __ps); |
106 | } |
107 | inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) { |
108 | __locale_guard __current(__loc); |
109 | return std::mbtowc(__pwc, __pmb, __max); |
110 | } |
111 | inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { |
112 | __locale_guard __current(__loc); |
113 | return std::mbrlen(__s, __n, __ps); |
114 | } |
115 | inline _LIBCPP_HIDE_FROM_ABI size_t |
116 | __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) { |
117 | __locale_guard __current(__loc); |
118 | return ::mbsrtowcs(__dest, __src, __len, __ps); |
119 | } |
120 | # endif // _LIBCPP_HAS_WIDE_CHARACTERS |
121 | #endif // _LIBCPP_BUILDING_LIBRARY |
122 | |
123 | _LIBCPP_DIAGNOSTIC_PUSH |
124 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") |
125 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates |
126 | #ifdef _LIBCPP_COMPILER_CLANG_BASED |
127 | # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__) |
128 | #else |
129 | # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */ |
130 | #endif |
131 | |
132 | template <class... _Args> |
133 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf( |
134 | char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) { |
135 | __locale_guard __current(__loc); |
136 | return std::snprintf(__s, __n, __format, std::forward<_Args>(__args)...); |
137 | } |
138 | template <class... _Args> |
139 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf( |
140 | char** __s, __locale_t __loc, const char* __format, _Args&&... __args) { |
141 | __locale_guard __current(__loc); |
142 | return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard |
143 | } |
144 | template <class... _Args> |
145 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf( |
146 | const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) { |
147 | __locale_guard __current(__loc); |
148 | return std::sscanf(__s, __format, std::forward<_Args>(__args)...); |
149 | } |
150 | |
151 | _LIBCPP_DIAGNOSTIC_POP |
152 | #undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT |
153 | |
154 | } // namespace __locale |
155 | _LIBCPP_END_NAMESPACE_STD |
156 | |
157 | #include <__locale_dir/support/no_locale/characters.h> |
158 | #include <__locale_dir/support/no_locale/strtonum.h> |
159 | |
160 | #endif // _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H |
161 |
Warning: This file is not a C or C++ file. It does not have highlighting.