aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h')
-rw-r--r--contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h67
1 files changed, 33 insertions, 34 deletions
diff --git a/contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h b/contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h
index efe674b5e7b3..b7e3be756e71 100644
--- a/contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h
+++ b/contrib/llvm-project/libcxx/include/__locale_dir/locale_base_api/locale_guard.h
@@ -36,42 +36,41 @@ private:
};
#elif defined(_LIBCPP_MSVCRT_LIKE)
struct __libcpp_locale_guard {
- __libcpp_locale_guard(locale_t __l) :
- __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
- // Setting the locale can be expensive even when the locale given is
- // already the current locale, so do an explicit check to see if the
- // current locale is already the one we want.
- const char* __lc = __setlocale(nullptr);
- // If every category is the same, the locale string will simply be the
- // locale name, otherwise it will be a semicolon-separated string listing
- // each category. In the second case, we know at least one category won't
- // be what we want, so we only have to check the first case.
- if (std::strcmp(__l.__get_locale(), __lc) != 0) {
- __locale_all = _strdup(__lc);
- if (__locale_all == nullptr)
- __throw_bad_alloc();
- __setlocale(__l.__get_locale());
- }
- }
- ~__libcpp_locale_guard() {
- // The CRT documentation doesn't explicitly say, but setlocale() does the
- // right thing when given a semicolon-separated list of locale settings
- // for the different categories in the same format as returned by
- // setlocale(LC_ALL, nullptr).
- if (__locale_all != nullptr) {
- __setlocale(__locale_all);
- free(__locale_all);
- }
- _configthreadlocale(__status);
- }
- static const char* __setlocale(const char* __locale) {
- const char* __new_locale = setlocale(LC_ALL, __locale);
- if (__new_locale == nullptr)
+ __libcpp_locale_guard(locale_t __l) : __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
+ // Setting the locale can be expensive even when the locale given is
+ // already the current locale, so do an explicit check to see if the
+ // current locale is already the one we want.
+ const char* __lc = __setlocale(nullptr);
+ // If every category is the same, the locale string will simply be the
+ // locale name, otherwise it will be a semicolon-separated string listing
+ // each category. In the second case, we know at least one category won't
+ // be what we want, so we only have to check the first case.
+ if (std::strcmp(__l.__get_locale(), __lc) != 0) {
+ __locale_all = _strdup(__lc);
+ if (__locale_all == nullptr)
__throw_bad_alloc();
- return __new_locale;
+ __setlocale(__l.__get_locale());
+ }
+ }
+ ~__libcpp_locale_guard() {
+ // The CRT documentation doesn't explicitly say, but setlocale() does the
+ // right thing when given a semicolon-separated list of locale settings
+ // for the different categories in the same format as returned by
+ // setlocale(LC_ALL, nullptr).
+ if (__locale_all != nullptr) {
+ __setlocale(__locale_all);
+ free(__locale_all);
}
- int __status;
- char* __locale_all = nullptr;
+ _configthreadlocale(__status);
+ }
+ static const char* __setlocale(const char* __locale) {
+ const char* __new_locale = setlocale(LC_ALL, __locale);
+ if (__new_locale == nullptr)
+ __throw_bad_alloc();
+ return __new_locale;
+ }
+ int __status;
+ char* __locale_all = nullptr;
};
#endif