2626# pragma GCC system_header
2727#endif
2828
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-
3929_LIBCPP_BEGIN_NAMESPACE_STD
4030namespace __locale {
4131
32+ using __lconv_t = std::lconv;
33+
4234class __lconv_storage {
4335public:
44- __lconv_storage (const lconv * __lc_input) {
36+ __lconv_storage (const __lconv_t * __lc_input) {
4537 __lc_ = *__lc_input;
4638
4739 __decimal_point_ = __lc_input->decimal_point ;
@@ -67,10 +59,10 @@ class __lconv_storage {
6759 __lc_.negative_sign = const_cast <char *>(__negative_sign_.c_str ());
6860 }
6961
70- std::lconv * __get () { return &__lc_; }
62+ __lconv_t * __get () { return &__lc_; }
7163
7264private:
73- std::lconv __lc_;
65+ __lconv_t __lc_;
7466 std::string __decimal_point_;
7567 std::string __thousands_sep_;
7668 std::string __grouping_;
@@ -86,6 +78,18 @@ class __lconv_storage {
8678//
8779// Locale management
8880//
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+
8993class __locale_t {
9094public:
9195 __locale_t () : __locale_(nullptr ), __locale_str_(nullptr ), __lc_(nullptr ) {}
@@ -137,7 +141,7 @@ class __locale_t {
137141
138142 operator ::_locale_t () const { return __locale_; }
139143
140- std::lconv * __store_lconv (const std::lconv * __input_lc) {
144+ __lconv_t * __store_lconv (const __lconv_t * __input_lc) {
141145 delete __lc_;
142146 __lc_ = new __lconv_storage (__input_lc);
143147 return __lc_->__get ();
@@ -151,7 +155,13 @@ class __locale_t {
151155
152156_LIBCPP_EXPORTED_FROM_ABI __locale_t __newlocale (int __mask, const char * __locale, __locale_t __base);
153157inline _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);
155165
156166//
157167// Strtonum functions
@@ -292,7 +302,7 @@ struct __locale_guard {
292302 // Setting the locale can be expensive even when the locale given is
293303 // already the current locale, so do an explicit check to see if the
294304 // current locale is already the one we want.
295- const char * __lc = __setlocale (nullptr );
305+ const char * __lc = __locale:: __setlocale (LC_ALL, nullptr );
296306 // If every category is the same, the locale string will simply be the
297307 // locale name, otherwise it will be a semicolon-separated string listing
298308 // each category. In the second case, we know at least one category won't
@@ -301,7 +311,7 @@ struct __locale_guard {
301311 __locale_all = _strdup (__lc);
302312 if (__locale_all == nullptr )
303313 __throw_bad_alloc ();
304- __setlocale (__l.__get_locale ());
314+ __locale:: __setlocale (LC_ALL, __l.__get_locale ());
305315 }
306316 }
307317 _LIBCPP_HIDE_FROM_ABI ~__locale_guard () {
@@ -310,17 +320,11 @@ struct __locale_guard {
310320 // for the different categories in the same format as returned by
311321 // setlocale(LC_ALL, nullptr).
312322 if (__locale_all != nullptr ) {
313- __setlocale (__locale_all);
323+ __locale:: __setlocale (LC_ALL, __locale_all);
314324 free (__locale_all);
315325 }
316326 _configthreadlocale (__status);
317327 }
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- }
324328 int __status;
325329 char * __locale_all = nullptr ;
326330};
0 commit comments