26
26
# pragma GCC system_header
27
27
#endif
28
28
29
- #define _CATMASK (n ) ((1 << (n)) >> 1 )
30
- #define LC_COLLATE_MASK _CATMASK (LC_COLLATE)
31
- #define LC_CTYPE_MASK _CATMASK (LC_CTYPE)
32
- #define LC_MONETARY_MASK _CATMASK (LC_MONETARY)
33
- #define LC_NUMERIC_MASK _CATMASK (LC_NUMERIC)
34
- #define LC_TIME_MASK _CATMASK (LC_TIME)
35
- #define LC_MESSAGES_MASK _CATMASK (6 )
36
- #define LC_ALL_MASK \
37
- (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MESSAGES_MASK | LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK)
38
-
39
29
_LIBCPP_BEGIN_NAMESPACE_STD
40
30
namespace __locale {
41
31
32
+ using __lconv_t = std::lconv;
33
+
42
34
class __lconv_storage {
43
35
public:
44
- __lconv_storage (const lconv * __lc_input) {
36
+ __lconv_storage (const __lconv_t * __lc_input) {
45
37
__lc_ = *__lc_input;
46
38
47
39
__decimal_point_ = __lc_input->decimal_point ;
@@ -67,10 +59,10 @@ class __lconv_storage {
67
59
__lc_.negative_sign = const_cast <char *>(__negative_sign_.c_str ());
68
60
}
69
61
70
- std::lconv * __get () { return &__lc_; }
62
+ __lconv_t * __get () { return &__lc_; }
71
63
72
64
private:
73
- std::lconv __lc_;
65
+ __lconv_t __lc_;
74
66
std::string __decimal_point_;
75
67
std::string __thousands_sep_;
76
68
std::string __grouping_;
@@ -86,6 +78,18 @@ class __lconv_storage {
86
78
//
87
79
// Locale management
88
80
//
81
+ #define _CATMASK (n ) ((1 << (n)) >> 1 )
82
+ #define _LIBCPP_COLLATE_MASK _CATMASK (LC_COLLATE)
83
+ #define _LIBCPP_CTYPE_MASK _CATMASK (LC_CTYPE)
84
+ #define _LIBCPP_MONETARY_MASK _CATMASK (LC_MONETARY)
85
+ #define _LIBCPP_NUMERIC_MASK _CATMASK (LC_NUMERIC)
86
+ #define _LIBCPP_TIME_MASK _CATMASK (LC_TIME)
87
+ #define _LIBCPP_MESSAGES_MASK _CATMASK (6 )
88
+ #define _LIBCPP_ALL_MASK \
89
+ (_LIBCPP_COLLATE_MASK | _LIBCPP_CTYPE_MASK | _LIBCPP_MESSAGES_MASK | _LIBCPP_MONETARY_MASK | _LIBCPP_NUMERIC_MASK | \
90
+ _LIBCPP_TIME_MASK)
91
+ #define _LIBCPP_LC_ALL LC_ALL
92
+
89
93
class __locale_t {
90
94
public:
91
95
__locale_t () : __locale_(nullptr ), __locale_str_(nullptr ), __lc_(nullptr ) {}
@@ -137,7 +141,7 @@ class __locale_t {
137
141
138
142
operator ::_locale_t () const { return __locale_; }
139
143
140
- std::lconv * __store_lconv (const std::lconv * __input_lc) {
144
+ __lconv_t * __store_lconv (const __lconv_t * __input_lc) {
141
145
delete __lc_;
142
146
__lc_ = new __lconv_storage (__input_lc);
143
147
return __lc_->__get ();
@@ -151,7 +155,13 @@ class __locale_t {
151
155
152
156
_LIBCPP_EXPORTED_FROM_ABI __locale_t __newlocale (int __mask, const char * __locale, __locale_t __base);
153
157
inline _LIBCPP_HIDE_FROM_ABI void __freelocale (__locale_t __loc) { ::_free_locale (__loc); }
154
- _LIBCPP_EXPORTED_FROM_ABI lconv* __localeconv (__locale_t & __loc);
158
+ inline _LIBCPP_HIDE_FROM_ABI char * __setlocale (int __category, const char * __locale) {
159
+ char * __new_locale = ::setlocale (__category, __locale);
160
+ if (__new_locale == nullptr )
161
+ std::__throw_bad_alloc ();
162
+ return __new_locale;
163
+ }
164
+ _LIBCPP_EXPORTED_FROM_ABI __lconv_t * __localeconv (__locale_t & __loc);
155
165
156
166
//
157
167
// Strtonum functions
@@ -292,7 +302,7 @@ struct __locale_guard {
292
302
// Setting the locale can be expensive even when the locale given is
293
303
// already the current locale, so do an explicit check to see if the
294
304
// current locale is already the one we want.
295
- const char * __lc = __setlocale (nullptr );
305
+ const char * __lc = __locale:: __setlocale (LC_ALL, nullptr );
296
306
// If every category is the same, the locale string will simply be the
297
307
// locale name, otherwise it will be a semicolon-separated string listing
298
308
// each category. In the second case, we know at least one category won't
@@ -301,7 +311,7 @@ struct __locale_guard {
301
311
__locale_all = _strdup (__lc);
302
312
if (__locale_all == nullptr )
303
313
__throw_bad_alloc ();
304
- __setlocale (__l.__get_locale ());
314
+ __locale:: __setlocale (LC_ALL, __l.__get_locale ());
305
315
}
306
316
}
307
317
_LIBCPP_HIDE_FROM_ABI ~__locale_guard () {
@@ -310,17 +320,11 @@ struct __locale_guard {
310
320
// for the different categories in the same format as returned by
311
321
// setlocale(LC_ALL, nullptr).
312
322
if (__locale_all != nullptr ) {
313
- __setlocale (__locale_all);
323
+ __locale:: __setlocale (LC_ALL, __locale_all);
314
324
free (__locale_all);
315
325
}
316
326
_configthreadlocale (__status);
317
327
}
318
- _LIBCPP_HIDE_FROM_ABI static const char * __setlocale (const char * __locale) {
319
- const char * __new_locale = setlocale (LC_ALL, __locale);
320
- if (__new_locale == nullptr )
321
- __throw_bad_alloc ();
322
- return __new_locale;
323
- }
324
328
int __status;
325
329
char * __locale_all = nullptr ;
326
330
};
0 commit comments