mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Release Cosmopolitan v3.6.0
This release is an atomic upgrade to GCC 14.1.0 with C23 and C++23
This commit is contained in:
parent
62ace3623a
commit
5660ec4741
1585 changed files with 117353 additions and 271644 deletions
100
third_party/libcxx/__locale_dir/locale_base_api.h
vendored
Normal file
100
third_party/libcxx/__locale_dir/locale_base_api.h
vendored
Normal file
|
@ -0,0 +1,100 @@
|
|||
//===-----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
|
||||
#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if defined(_LIBCPP_MSVCRT_LIKE)
|
||||
// # include <__locale_dir/locale_base_api/win32.h>
|
||||
#elif defined(_AIX) || defined(__MVS__)
|
||||
// # include <__locale_dir/locale_base_api/ibm.h>
|
||||
#elif defined(__ANDROID__)
|
||||
// # include <__locale_dir/locale_base_api/android.h>
|
||||
#elif defined(__sun__)
|
||||
// # include <__locale_dir/locale_base_api/solaris.h>
|
||||
#elif defined(_NEWLIB_VERSION)
|
||||
// # include <__locale_dir/locale_base_api/newlib.h>
|
||||
#elif defined(__OpenBSD__)
|
||||
// # include <__locale_dir/locale_base_api/openbsd.h>
|
||||
#elif defined(__Fuchsia__)
|
||||
// # include <__locale_dir/locale_base_api/fuchsia.h>
|
||||
#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC)
|
||||
// # include <__locale_dir/locale_base_api/musl.h>
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__)
|
||||
# include <xlocale.h>
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
/*
|
||||
The platform-specific headers have to provide the following interface:
|
||||
|
||||
// TODO: rename this to __libcpp_locale_t
|
||||
using locale_t = implementation-defined;
|
||||
|
||||
implementation-defined __libcpp_mb_cur_max_l(locale_t);
|
||||
wint_t __libcpp_btowc_l(int, locale_t);
|
||||
int __libcpp_wctob_l(wint_t, locale_t);
|
||||
size_t __libcpp_wcsnrtombs_l(char* dest, const wchar_t** src, size_t wide_char_count, size_t len, mbstate_t, locale_t);
|
||||
size_t __libcpp_wcrtomb_l(char* str, wchar_t wide_char, mbstate_t*, locale_t);
|
||||
size_t __libcpp_mbsnrtowcs_l(wchar_t* dest, const char** src, size_t max_out, size_t len, mbstate_t*, locale_t);
|
||||
size_t __libcpp_mbrtowc_l(wchar_t* dest, cosnt char* src, size_t count, mbstate_t*, locale_t);
|
||||
int __libcpp_mbtowc_l(wchar_t* dest, const char* src, size_t count, locale_t);
|
||||
size_t __libcpp_mbrlen_l(const char* str, size_t count, mbstate_t*, locale_t);
|
||||
lconv* __libcpp_localeconv_l(locale_t);
|
||||
size_t __libcpp_mbsrtowcs_l(wchar_t* dest, const char** src, size_t len, mbstate_t*, locale_t);
|
||||
int __libcpp_snprintf_l(char* dest, size_t buff_size, locale_t, const char* format, ...);
|
||||
int __libcpp_asprintf_l(char** dest, locale_t, const char* format, ...);
|
||||
int __libcpp_sscanf_l(const char* dest, locale_t, const char* format, ...);
|
||||
|
||||
// TODO: change these to reserved names
|
||||
float strtof_l(const char* str, char** str_end, locale_t);
|
||||
double strtod_l(const char* str, char** str_end, locale_t);
|
||||
long double strtold_l(const char* str, char** str_end, locale_t);
|
||||
long long strtoll_l(const char* str, char** str_end, locale_t);
|
||||
unsigned long long strtoull_l(const char* str, char** str_end, locale_t);
|
||||
|
||||
locale_t newlocale(int category_mask, const char* locale, locale_t base);
|
||||
void freelocale(locale_t);
|
||||
|
||||
int islower_l(int ch, locale_t);
|
||||
int isupper_l(int ch, locale_t);
|
||||
int isdigit_l(int ch, locale_t);
|
||||
int isxdigit_l(int ch, locale_t);
|
||||
int strcoll_l(const char* lhs, const char* rhs, locale_t);
|
||||
size_t strxfrm_l(char* dst, const char* src, size_t n, locale_t);
|
||||
int wcscoll_l(const char* lhs, const char* rhs, locale_t);
|
||||
size_t wcsxfrm_l(wchar_t* dst, const wchar_t* src, size_t n, locale_t);
|
||||
int toupper_l(int ch, locale_t);
|
||||
int tolower_l(int ch, locale_t);
|
||||
int iswspace_l(wint_t ch, locale_t);
|
||||
int iswprint_l(wint_t ch, locale_t);
|
||||
int iswcntrl_l(wint_t ch, locale_t);
|
||||
int iswupper_l(wint_t ch, locale_t);
|
||||
int iswlower_l(wint_t ch, locale_t);
|
||||
int iswalpha_l(wint_t ch, locale_t);
|
||||
int iswblank_l(wint_t ch, locale_t);
|
||||
int iswdigit_l(wint_t ch, locale_t);
|
||||
int iswpunct_l(wint_t ch, locale_t);
|
||||
int iswxdigit_l(wint_t ch, locale_t);
|
||||
wint_t towupper_l(wint_t ch, locale_t);
|
||||
wint_t towlower_l(wint_t ch, locale_t);
|
||||
size_t strftime_l(char* str, size_t len, const char* format, const tm*, locale_t);
|
||||
|
||||
|
||||
These functions are equivalent to their C counterparts,
|
||||
except that locale_t is used instead of the current global locale.
|
||||
|
||||
The variadic functions may be implemented as templates with a parameter pack instead of variadic functions.
|
||||
*/
|
||||
|
||||
#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
|
|
@ -14,23 +14,25 @@
|
|||
#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H
|
||||
#define _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc)
|
||||
#define __libcpp_btowc_l(ch, loc) btowc_l(ch, loc)
|
||||
#define __libcpp_wctob_l(wch, loc) wctob_l(wch, loc)
|
||||
#define __libcpp_wcsnrtombs_l(dst, src, nwc, len, ps, loc) wcsnrtombs_l(dst, src, nwc, len, ps, loc)
|
||||
#define __libcpp_wcrtomb_l(src, wc, ps, loc) wcrtomb_l(src, wc, ps, loc)
|
||||
#define __libcpp_mbsnrtowcs_l(dst, src, nms, len, ps, loc) mbsnrtowcs_l(dst, src, nms, len, ps, loc)
|
||||
#define __libcpp_mbrtowc_l(pwc, s, n, ps, l) mbrtowc_l(pwc, s, n, ps, l)
|
||||
#define __libcpp_mbtowc_l(pwc, pmb, max, l) mbtowc_l(pwc, pmb, max, l)
|
||||
#define __libcpp_mbrlen_l(s, n, ps, l) mbrlen_l(s, n, ps, l)
|
||||
#define __libcpp_localeconv_l(l) localeconv_l(l)
|
||||
#define __libcpp_mbsrtowcs_l(dest, src, len, ps, l) mbsrtowcs_l(dest, src, len, ps, l)
|
||||
#define __libcpp_snprintf_l(...) snprintf_l(__VA_ARGS__)
|
||||
#define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__)
|
||||
#define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__)
|
||||
#define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc)
|
||||
#define __libcpp_btowc_l(ch, loc) btowc_l(ch, loc)
|
||||
#define __libcpp_wctob_l(wch, loc) wctob_l(wch, loc)
|
||||
#define __libcpp_wcsnrtombs_l(dst, src, nwc, len, ps, loc) wcsnrtombs_l(dst, src, nwc, len, ps, loc)
|
||||
#define __libcpp_wcrtomb_l(src, wc, ps, loc) wcrtomb_l(src, wc, ps, loc)
|
||||
#define __libcpp_mbsnrtowcs_l(dst, src, nms, len, ps, loc) mbsnrtowcs_l(dst, src, nms, len, ps, loc)
|
||||
#define __libcpp_mbrtowc_l(pwc, s, n, ps, l) mbrtowc_l(pwc, s, n, ps, l)
|
||||
#define __libcpp_mbtowc_l(pwc, pmb, max, l) mbtowc_l(pwc, pmb, max, l)
|
||||
#define __libcpp_mbrlen_l(s, n, ps, l) mbrlen_l(s, n, ps, l)
|
||||
#define __libcpp_localeconv_l(l) localeconv_l(l)
|
||||
#define __libcpp_mbsrtowcs_l(dest, src, len, ps, l) mbsrtowcs_l(dest, src, len, ps, l)
|
||||
#define __libcpp_snprintf_l(...) snprintf_l(__VA_ARGS__)
|
||||
#define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__)
|
||||
#define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__)
|
||||
|
||||
#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H
|
||||
|
|
|
@ -28,119 +28,97 @@
|
|||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return MB_CUR_MAX;
|
||||
inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return MB_CUR_MAX;
|
||||
}
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
wint_t __libcpp_btowc_l(int __c, locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return btowc(__c);
|
||||
inline _LIBCPP_HIDE_FROM_ABI wint_t __libcpp_btowc_l(int __c, locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return btowc(__c);
|
||||
}
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
int __libcpp_wctob_l(wint_t __c, locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return wctob(__c);
|
||||
inline _LIBCPP_HIDE_FROM_ABI int __libcpp_wctob_l(wint_t __c, locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return wctob(__c);
|
||||
}
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
|
||||
size_t __len, mbstate_t *__ps, locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
|
||||
inline _LIBCPP_HIDE_FROM_ABI size_t
|
||||
__libcpp_wcsnrtombs_l(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
|
||||
}
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return wcrtomb(__s, __wc, __ps);
|
||||
inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcrtomb_l(char* __s, wchar_t __wc, mbstate_t* __ps, locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return wcrtomb(__s, __wc, __ps);
|
||||
}
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
|
||||
size_t __len, mbstate_t *__ps, locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
|
||||
inline _LIBCPP_HIDE_FROM_ABI size_t
|
||||
__libcpp_mbsnrtowcs_l(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
|
||||
}
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
|
||||
mbstate_t *__ps, locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbrtowc(__pwc, __s, __n, __ps);
|
||||
inline _LIBCPP_HIDE_FROM_ABI size_t
|
||||
__libcpp_mbrtowc_l(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbrtowc(__pwc, __s, __n, __ps);
|
||||
}
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbtowc(__pwc, __pmb, __max);
|
||||
inline _LIBCPP_HIDE_FROM_ABI int __libcpp_mbtowc_l(wchar_t* __pwc, const char* __pmb, size_t __max, locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbtowc(__pwc, __pmb, __max);
|
||||
}
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbrlen(__s, __n, __ps);
|
||||
inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbrlen_l(const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbrlen(__s, __n, __ps);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
lconv *__libcpp_localeconv_l(locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return localeconv();
|
||||
inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return localeconv();
|
||||
}
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
|
||||
mbstate_t *__ps, locale_t __l)
|
||||
{
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbsrtowcs(__dest, __src, __len, __ps);
|
||||
inline _LIBCPP_HIDE_FROM_ABI size_t
|
||||
__libcpp_mbsrtowcs_l(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, locale_t __l) {
|
||||
__libcpp_locale_guard __current(__l);
|
||||
return mbsrtowcs(__dest, __src, __len, __ps);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5)
|
||||
int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
|
||||
va_list __va;
|
||||
va_start(__va, __format);
|
||||
__libcpp_locale_guard __current(__l);
|
||||
int __res = vsnprintf(__s, __n, __format, __va);
|
||||
va_end(__va);
|
||||
return __res;
|
||||
inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __libcpp_snprintf_l(
|
||||
char* __s, size_t __n, locale_t __l, const char* __format, ...) {
|
||||
va_list __va;
|
||||
va_start(__va, __format);
|
||||
__libcpp_locale_guard __current(__l);
|
||||
int __res = vsnprintf(__s, __n, __format, __va);
|
||||
va_end(__va);
|
||||
return __res;
|
||||
}
|
||||
|
||||
inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
|
||||
int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
|
||||
va_list __va;
|
||||
va_start(__va, __format);
|
||||
__libcpp_locale_guard __current(__l);
|
||||
int __res = vasprintf(__s, __format, __va);
|
||||
va_end(__va);
|
||||
return __res;
|
||||
inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l(
|
||||
char** __s, locale_t __l, const char* __format, ...) {
|
||||
va_list __va;
|
||||
va_start(__va, __format);
|
||||
__libcpp_locale_guard __current(__l);
|
||||
int __res = vasprintf(__s, __format, __va);
|
||||
va_end(__va);
|
||||
return __res;
|
||||
}
|
||||
|
||||
inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4)
|
||||
int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
|
||||
va_list __va;
|
||||
va_start(__va, __format);
|
||||
__libcpp_locale_guard __current(__l);
|
||||
int __res = vsscanf(__s, __format, __va);
|
||||
va_end(__va);
|
||||
return __res;
|
||||
inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l(
|
||||
const char* __s, locale_t __l, const char* __format, ...) {
|
||||
va_list __va;
|
||||
va_start(__va, __format);
|
||||
__libcpp_locale_guard __current(__l);
|
||||
int __res = vsscanf(__s, __format, __va);
|
||||
va_end(__va);
|
||||
return __res;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define _LIBCPP___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H
|
||||
|
||||
#include <__config>
|
||||
#include <__locale> // for locale_t
|
||||
#include <clocale>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
|
@ -20,57 +21,55 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
|
||||
#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
|
||||
struct __libcpp_locale_guard {
|
||||
_LIBCPP_INLINE_VISIBILITY __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
|
||||
_LIBCPP_HIDE_FROM_ABI __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY ~__libcpp_locale_guard() {
|
||||
_LIBCPP_HIDE_FROM_ABI ~__libcpp_locale_guard() {
|
||||
if (__old_loc_)
|
||||
uselocale(__old_loc_);
|
||||
}
|
||||
|
||||
locale_t __old_loc_;
|
||||
|
||||
private:
|
||||
__libcpp_locale_guard(__libcpp_locale_guard const&);
|
||||
__libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
|
||||
__libcpp_locale_guard(__libcpp_locale_guard const&) = delete;
|
||||
__libcpp_locale_guard& operator=(__libcpp_locale_guard const&) = delete;
|
||||
};
|
||||
#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 (_VSTD::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());
|
||||
}
|
||||
int __status;
|
||||
char* __locale_all = nullptr;
|
||||
}
|
||||
~__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)
|
||||
__throw_bad_alloc();
|
||||
return __new_locale;
|
||||
}
|
||||
int __status;
|
||||
char* __locale_all = nullptr;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue