File indexing completed on 2026-05-03 08:13:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H
0011 #define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H
0012
0013 #if defined(__MVS__)
0014 # include <__support/ibm/locale_mgmt_zos.h>
0015 #endif
0016
0017 #include <locale.h>
0018 #include <stdarg.h>
0019 #include <stdio.h>
0020
0021 #include "cstdlib"
0022
0023 #if defined(__MVS__)
0024 # include <wctype.h>
0025
0026 # include <__support/xlocale/__posix_l_fallback.h>
0027 #endif
0028
0029 namespace {
0030
0031 struct __setAndRestore {
0032 explicit __setAndRestore(locale_t locale) {
0033 if (locale == (locale_t)0) {
0034 __cloc = newlocale(LC_ALL_MASK, "C", (locale_t)0);
0035 __stored = uselocale(__cloc);
0036 } else {
0037 __stored = uselocale(locale);
0038 }
0039 }
0040
0041 ~__setAndRestore() {
0042 uselocale(__stored);
0043 if (__cloc)
0044 freelocale(__cloc);
0045 }
0046
0047 private:
0048 locale_t __stored = (locale_t)0;
0049 locale_t __cloc = (locale_t)0;
0050 };
0051
0052 }
0053
0054
0055
0056 inline _LIBCPP_HIDE_FROM_ABI long long strtoll_l(const char* __nptr, char** __endptr, int __base, locale_t locale) {
0057 __setAndRestore __newloc(locale);
0058 return ::strtoll(__nptr, __endptr, __base);
0059 }
0060
0061 inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t locale) {
0062 __setAndRestore __newloc(locale);
0063 return ::strtod(__nptr, __endptr);
0064 }
0065
0066 inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t locale) {
0067 __setAndRestore __newloc(locale);
0068 return ::strtof(__nptr, __endptr);
0069 }
0070
0071 inline _LIBCPP_HIDE_FROM_ABI long double strtold_l(const char* __nptr, char** __endptr, locale_t locale) {
0072 __setAndRestore __newloc(locale);
0073 return ::strtold(__nptr, __endptr);
0074 }
0075
0076 inline _LIBCPP_HIDE_FROM_ABI unsigned long long
0077 strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t locale) {
0078 __setAndRestore __newloc(locale);
0079 return ::strtoull(__nptr, __endptr, __base);
0080 }
0081
0082 inline _LIBCPP_HIDE_FROM_ABI
0083 _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char* fmt, va_list ap) {
0084 const size_t buff_size = 256;
0085 if ((*strp = (char*)malloc(buff_size)) == nullptr) {
0086 return -1;
0087 }
0088
0089 va_list ap_copy;
0090
0091 #if defined(_LIBCPP_CXX03_LANG) && __has_builtin(__builtin_va_copy)
0092 __builtin_va_copy(ap_copy, ap);
0093 #else
0094 va_copy(ap_copy, ap);
0095 #endif
0096 int str_size = vsnprintf(*strp, buff_size, fmt, ap_copy);
0097 va_end(ap_copy);
0098
0099 if ((size_t)str_size >= buff_size) {
0100 if ((*strp = (char*)realloc(*strp, str_size + 1)) == nullptr) {
0101 return -1;
0102 }
0103 str_size = vsnprintf(*strp, str_size + 1, fmt, ap);
0104 }
0105 return str_size;
0106 }
0107
0108 #endif