Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:54

0001 //===-----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
0010 #define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
0011 
0012 #include <__config>
0013 
0014 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0015 #  pragma GCC system_header
0016 #endif
0017 
0018 // The platform-specific headers have to provide the following interface.
0019 //
0020 // These functions are equivalent to their C counterparts, except that __locale::__locale_t
0021 // is used instead of the current global locale.
0022 //
0023 // Variadic functions may be implemented as templates with a parameter pack instead
0024 // of C-style variadic functions.
0025 //
0026 // Most of these functions are only required when building the library. Functions that are also
0027 // required when merely using the headers are marked as such below.
0028 //
0029 // TODO: __localeconv shouldn't take a reference, but the Windows implementation doesn't allow copying __locale_t
0030 // TODO: Eliminate the need for any of these functions from the headers.
0031 //
0032 // Locale management
0033 // -----------------
0034 // namespace __locale {
0035 //  using __locale_t = implementation-defined;  // required by the headers
0036 //  using __lconv_t  = implementation-defined;
0037 //  __locale_t  __newlocale(int, const char*, __locale_t);
0038 //  void        __freelocale(__locale_t);
0039 //  char*       __setlocale(int, const char*);
0040 //  __lconv_t*  __localeconv(__locale_t&);
0041 // }
0042 //
0043 // // required by the headers
0044 // #define _LIBCPP_COLLATE_MASK   /* implementation-defined */
0045 // #define _LIBCPP_CTYPE_MASK     /* implementation-defined */
0046 // #define _LIBCPP_MONETARY_MASK  /* implementation-defined */
0047 // #define _LIBCPP_NUMERIC_MASK   /* implementation-defined */
0048 // #define _LIBCPP_TIME_MASK      /* implementation-defined */
0049 // #define _LIBCPP_MESSAGES_MASK  /* implementation-defined */
0050 // #define _LIBCPP_ALL_MASK       /* implementation-defined */
0051 // #define _LIBCPP_LC_ALL         /* implementation-defined */
0052 //
0053 // Strtonum functions
0054 // ------------------
0055 // namespace __locale {
0056 //  // required by the headers
0057 //  float               __strtof(const char*, char**, __locale_t);
0058 //  double              __strtod(const char*, char**, __locale_t);
0059 //  long double         __strtold(const char*, char**, __locale_t);
0060 //  long long           __strtoll(const char*, char**, __locale_t);
0061 //  unsigned long long  __strtoull(const char*, char**, __locale_t);
0062 // }
0063 //
0064 // Character manipulation functions
0065 // --------------------------------
0066 // namespace __locale {
0067 //  int     __islower(int, __locale_t);
0068 //  int     __isupper(int, __locale_t);
0069 //  int     __isdigit(int, __locale_t);  // required by the headers
0070 //  int     __isxdigit(int, __locale_t); // required by the headers
0071 //  int     __toupper(int, __locale_t);
0072 //  int     __tolower(int, __locale_t);
0073 //  int     __strcoll(const char*, const char*, __locale_t);
0074 //  size_t  __strxfrm(char*, const char*, size_t, __locale_t);
0075 //
0076 //  int     __iswctype(wint_t, wctype_t, __locale_t);
0077 //  int     __iswspace(wint_t, __locale_t);
0078 //  int     __iswprint(wint_t, __locale_t);
0079 //  int     __iswcntrl(wint_t, __locale_t);
0080 //  int     __iswupper(wint_t, __locale_t);
0081 //  int     __iswlower(wint_t, __locale_t);
0082 //  int     __iswalpha(wint_t, __locale_t);
0083 //  int     __iswblank(wint_t, __locale_t);
0084 //  int     __iswdigit(wint_t, __locale_t);
0085 //  int     __iswpunct(wint_t, __locale_t);
0086 //  int     __iswxdigit(wint_t, __locale_t);
0087 //  wint_t  __towupper(wint_t, __locale_t);
0088 //  wint_t  __towlower(wint_t, __locale_t);
0089 //  int     __wcscoll(const wchar_t*, const wchar_t*, __locale_t);
0090 //  size_t  __wcsxfrm(wchar_t*, const wchar_t*, size_t, __locale_t);
0091 //
0092 //  size_t  __strftime(char*, size_t, const char*, const tm*, __locale_t);
0093 // }
0094 //
0095 // Other functions
0096 // ---------------
0097 // namespace __locale {
0098 //  implementation-defined __mb_len_max(__locale_t);
0099 //  wint_t  __btowc(int, __locale_t);
0100 //  int     __wctob(wint_t, __locale_t);
0101 //  size_t  __wcsnrtombs(char*, const wchar_t**, size_t, size_t, mbstate_t*, __locale_t);
0102 //  size_t  __wcrtomb(char*, wchar_t, mbstate_t*, __locale_t);
0103 //  size_t  __mbsnrtowcs(wchar_t*, const char**, size_t, size_t, mbstate_t*, __locale_t);
0104 //  size_t  __mbrtowc(wchar_t*, const char*, size_t, mbstate_t*, __locale_t);
0105 //  int     __mbtowc(wchar_t*, const char*, size_t, __locale_t);
0106 //  size_t  __mbrlen(const char*, size_t, mbstate_t*, __locale_t);
0107 //  size_t  __mbsrtowcs(wchar_t*, const char**, size_t, mbstate_t*, __locale_t);
0108 //
0109 //  int     __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers
0110 //  int     __asprintf(char**, __locale_t, const char*, ...);        // required by the headers
0111 //  int     __sscanf(const char*, __locale_t, const char*, ...);     // required by the headers
0112 // }
0113 
0114 #if _LIBCPP_HAS_LOCALIZATION
0115 
0116 #  if defined(__APPLE__)
0117 #    include <__locale_dir/support/apple.h>
0118 #  elif defined(__FreeBSD__)
0119 #    include <__locale_dir/support/freebsd.h>
0120 #  elif defined(_LIBCPP_MSVCRT_LIKE)
0121 #    include <__locale_dir/support/windows.h>
0122 #  elif defined(__Fuchsia__)
0123 #    include <__locale_dir/support/fuchsia.h>
0124 #  else
0125 
0126 // TODO: This is a temporary definition to bridge between the old way we defined the locale base API
0127 //       (by providing global non-reserved names) and the new API. As we move individual platforms
0128 //       towards the new way of defining the locale base API, this should disappear since each platform
0129 //       will define those directly.
0130 #    if defined(_AIX) || defined(__MVS__)
0131 #      include <__locale_dir/locale_base_api/ibm.h>
0132 #    elif defined(__ANDROID__)
0133 #      include <__locale_dir/locale_base_api/android.h>
0134 #    elif defined(__OpenBSD__)
0135 #      include <__locale_dir/locale_base_api/openbsd.h>
0136 #    elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
0137 #      include <__locale_dir/locale_base_api/musl.h>
0138 #    endif
0139 
0140 #    include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
0141 
0142 #    include <__cstddef/size_t.h>
0143 #    include <__utility/forward.h>
0144 #    include <ctype.h>
0145 #    include <string.h>
0146 #    include <time.h>
0147 #    if _LIBCPP_HAS_WIDE_CHARACTERS
0148 #      include <wctype.h>
0149 #    endif
0150 _LIBCPP_BEGIN_NAMESPACE_STD
0151 namespace __locale {
0152 //
0153 // Locale management
0154 //
0155 #    define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
0156 #    define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
0157 #    define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
0158 #    define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
0159 #    define _LIBCPP_TIME_MASK LC_TIME_MASK
0160 #    define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
0161 #    define _LIBCPP_ALL_MASK LC_ALL_MASK
0162 #    define _LIBCPP_LC_ALL LC_ALL
0163 
0164 using __locale_t _LIBCPP_NODEBUG = locale_t;
0165 
0166 #    if defined(_LIBCPP_BUILDING_LIBRARY)
0167 using __lconv_t _LIBCPP_NODEBUG = lconv;
0168 
0169 inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) {
0170   return newlocale(__category_mask, __name, __loc);
0171 }
0172 
0173 inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) {
0174   return ::setlocale(__category, __locale);
0175 }
0176 
0177 inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { freelocale(__loc); }
0178 
0179 inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return __libcpp_localeconv_l(__loc); }
0180 #    endif // _LIBCPP_BUILDING_LIBRARY
0181 
0182 //
0183 // Strtonum functions
0184 //
0185 inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
0186   return strtof_l(__nptr, __endptr, __loc);
0187 }
0188 
0189 inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
0190   return strtod_l(__nptr, __endptr, __loc);
0191 }
0192 
0193 inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
0194   return strtold_l(__nptr, __endptr, __loc);
0195 }
0196 
0197 inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
0198   return strtoll_l(__nptr, __endptr, __base, __loc);
0199 }
0200 
0201 inline _LIBCPP_HIDE_FROM_ABI unsigned long long
0202 __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
0203   return strtoull_l(__nptr, __endptr, __base, __loc);
0204 }
0205 
0206 //
0207 // Character manipulation functions
0208 //
0209 #    if defined(_LIBCPP_BUILDING_LIBRARY)
0210 inline _LIBCPP_HIDE_FROM_ABI int __islower(int __ch, __locale_t __loc) { return islower_l(__ch, __loc); }
0211 inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __ch, __locale_t __loc) { return isupper_l(__ch, __loc); }
0212 #    endif
0213 
0214 inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __ch, __locale_t __loc) { return isdigit_l(__ch, __loc); }
0215 inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __ch, __locale_t __loc) { return isxdigit_l(__ch, __loc); }
0216 
0217 #    if defined(_LIBCPP_BUILDING_LIBRARY)
0218 inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) {
0219   return strcoll_l(__s1, __s2, __loc);
0220 }
0221 inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) {
0222   return strxfrm_l(__dest, __src, __n, __loc);
0223 }
0224 inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __ch, __locale_t __loc) { return toupper_l(__ch, __loc); }
0225 inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __ch, __locale_t __loc) { return tolower_l(__ch, __loc); }
0226 
0227 #      if _LIBCPP_HAS_WIDE_CHARACTERS
0228 inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __s1, const wchar_t* __s2, __locale_t __loc) {
0229   return wcscoll_l(__s1, __s2, __loc);
0230 }
0231 inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
0232   return wcsxfrm_l(__dest, __src, __n, __loc);
0233 }
0234 inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __ch, wctype_t __type, __locale_t __loc) {
0235   return iswctype_l(__ch, __type, __loc);
0236 }
0237 inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __ch, __locale_t __loc) { return iswspace_l(__ch, __loc); }
0238 inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __ch, __locale_t __loc) { return iswprint_l(__ch, __loc); }
0239 inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __ch, __locale_t __loc) { return iswcntrl_l(__ch, __loc); }
0240 inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __ch, __locale_t __loc) { return iswupper_l(__ch, __loc); }
0241 inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __ch, __locale_t __loc) { return iswlower_l(__ch, __loc); }
0242 inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __ch, __locale_t __loc) { return iswalpha_l(__ch, __loc); }
0243 inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __ch, __locale_t __loc) { return iswblank_l(__ch, __loc); }
0244 inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __ch, __locale_t __loc) { return iswdigit_l(__ch, __loc); }
0245 inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __ch, __locale_t __loc) { return iswpunct_l(__ch, __loc); }
0246 inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __ch, __locale_t __loc) { return iswxdigit_l(__ch, __loc); }
0247 inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __ch, __locale_t __loc) { return towupper_l(__ch, __loc); }
0248 inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __ch, __locale_t __loc) { return towlower_l(__ch, __loc); }
0249 #      endif
0250 
0251 inline _LIBCPP_HIDE_FROM_ABI size_t
0252 __strftime(char* __s, size_t __max, const char* __format, const tm* __tm, __locale_t __loc) {
0253   return strftime_l(__s, __max, __format, __tm, __loc);
0254 }
0255 
0256 //
0257 // Other functions
0258 //
0259 inline _LIBCPP_HIDE_FROM_ABI decltype(__libcpp_mb_cur_max_l(__locale_t())) __mb_len_max(__locale_t __loc) {
0260   return __libcpp_mb_cur_max_l(__loc);
0261 }
0262 #      if _LIBCPP_HAS_WIDE_CHARACTERS
0263 inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) { return __libcpp_btowc_l(__ch, __loc); }
0264 inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) { return __libcpp_wctob_l(__ch, __loc); }
0265 inline _LIBCPP_HIDE_FROM_ABI size_t
0266 __wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
0267   return __libcpp_wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __loc);
0268 }
0269 inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) {
0270   return __libcpp_wcrtomb_l(__s, __ch, __ps, __loc);
0271 }
0272 inline _LIBCPP_HIDE_FROM_ABI size_t
0273 __mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
0274   return __libcpp_mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __loc);
0275 }
0276 inline _LIBCPP_HIDE_FROM_ABI size_t
0277 __mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
0278   return __libcpp_mbrtowc_l(__pwc, __s, __n, __ps, __loc);
0279 }
0280 inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
0281   return __libcpp_mbtowc_l(__pwc, __pmb, __max, __loc);
0282 }
0283 inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
0284   return __libcpp_mbrlen_l(__s, __n, __ps, __loc);
0285 }
0286 inline _LIBCPP_HIDE_FROM_ABI size_t
0287 __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
0288   return __libcpp_mbsrtowcs_l(__dest, __src, __len, __ps, __loc);
0289 }
0290 #      endif // _LIBCPP_HAS_WIDE_CHARACTERS
0291 #    endif   // _LIBCPP_BUILDING_LIBRARY
0292 
0293 _LIBCPP_DIAGNOSTIC_PUSH
0294 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
0295 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
0296 #    ifdef _LIBCPP_COMPILER_CLANG_BASED
0297 #      define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
0298 #    else
0299 #      define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
0300 #    endif
0301 
0302 template <class... _Args>
0303 _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
0304     char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) {
0305   return std::__libcpp_snprintf_l(__s, __n, __loc, __format, std::forward<_Args>(__args)...);
0306 }
0307 template <class... _Args>
0308 _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(
0309     char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
0310   return std::__libcpp_asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
0311 }
0312 template <class... _Args>
0313 _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
0314     const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
0315   return std::__libcpp_sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
0316 }
0317 _LIBCPP_DIAGNOSTIC_POP
0318 #    undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
0319 
0320 } // namespace __locale
0321 _LIBCPP_END_NAMESPACE_STD
0322 
0323 #  endif // Compatibility definition of locale base APIs
0324 
0325 #endif // _LIBCPP_HAS_LOCALIZATION
0326 
0327 #endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H