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_SUPPORT_FUCHSIA_H
0010 #define _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
0011 
0012 #include <__config>
0013 #include <__utility/forward.h>
0014 #include <clocale> // uselocale & friends
0015 #include <cstdio>
0016 #include <cstdlib>
0017 #include <cwchar>
0018 
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 #  pragma GCC system_header
0021 #endif
0022 
0023 _LIBCPP_BEGIN_NAMESPACE_STD
0024 namespace __locale {
0025 
0026 struct __locale_guard {
0027   _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
0028 
0029   _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
0030     if (__old_loc_)
0031       ::uselocale(__old_loc_);
0032   }
0033 
0034   locale_t __old_loc_;
0035 
0036   __locale_guard(__locale_guard const&)            = delete;
0037   __locale_guard& operator=(__locale_guard const&) = delete;
0038 };
0039 
0040 //
0041 // Locale management
0042 //
0043 #define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
0044 #define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
0045 #define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
0046 #define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
0047 #define _LIBCPP_TIME_MASK LC_TIME_MASK
0048 #define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
0049 #define _LIBCPP_ALL_MASK LC_ALL_MASK
0050 #define _LIBCPP_LC_ALL LC_ALL
0051 
0052 using __locale_t = locale_t;
0053 
0054 #if defined(_LIBCPP_BUILDING_LIBRARY)
0055 using __lconv_t = std::lconv;
0056 
0057 inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) {
0058   return ::newlocale(__category_mask, __name, __loc);
0059 }
0060 
0061 inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
0062 
0063 inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) {
0064   return ::setlocale(__category, __locale);
0065 }
0066 
0067 inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
0068   __locale_guard __current(__loc);
0069   return std::localeconv();
0070 }
0071 
0072 //
0073 // Other functions
0074 //
0075 inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) {
0076   __locale_guard __current(__loc);
0077   return MB_CUR_MAX;
0078 }
0079 #  if _LIBCPP_HAS_WIDE_CHARACTERS
0080 inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) {
0081   __locale_guard __current(__loc);
0082   return std::btowc(__ch);
0083 }
0084 inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) {
0085   __locale_guard __current(__loc);
0086   return std::wctob(__ch);
0087 }
0088 inline _LIBCPP_HIDE_FROM_ABI size_t
0089 __wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
0090   __locale_guard __current(__loc);
0091   return ::wcsnrtombs(__dest, __src, __nwc, __len, __ps); // non-standard
0092 }
0093 inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) {
0094   __locale_guard __current(__loc);
0095   return std::wcrtomb(__s, __ch, __ps);
0096 }
0097 inline _LIBCPP_HIDE_FROM_ABI size_t
0098 __mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
0099   __locale_guard __current(__loc);
0100   return ::mbsnrtowcs(__dest, __src, __nms, __len, __ps); // non-standard
0101 }
0102 inline _LIBCPP_HIDE_FROM_ABI size_t
0103 __mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
0104   __locale_guard __current(__loc);
0105   return std::mbrtowc(__pwc, __s, __n, __ps);
0106 }
0107 inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
0108   __locale_guard __current(__loc);
0109   return std::mbtowc(__pwc, __pmb, __max);
0110 }
0111 inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
0112   __locale_guard __current(__loc);
0113   return std::mbrlen(__s, __n, __ps);
0114 }
0115 inline _LIBCPP_HIDE_FROM_ABI size_t
0116 __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
0117   __locale_guard __current(__loc);
0118   return ::mbsrtowcs(__dest, __src, __len, __ps);
0119 }
0120 #  endif // _LIBCPP_HAS_WIDE_CHARACTERS
0121 #endif   // _LIBCPP_BUILDING_LIBRARY
0122 
0123 _LIBCPP_DIAGNOSTIC_PUSH
0124 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
0125 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
0126 #ifdef _LIBCPP_COMPILER_CLANG_BASED
0127 #  define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
0128 #else
0129 #  define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
0130 #endif
0131 
0132 template <class... _Args>
0133 _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
0134     char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) {
0135   __locale_guard __current(__loc);
0136   return std::snprintf(__s, __n, __format, std::forward<_Args>(__args)...);
0137 }
0138 template <class... _Args>
0139 _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(
0140     char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
0141   __locale_guard __current(__loc);
0142   return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard
0143 }
0144 template <class... _Args>
0145 _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
0146     const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
0147   __locale_guard __current(__loc);
0148   return std::sscanf(__s, __format, std::forward<_Args>(__args)...);
0149 }
0150 
0151 _LIBCPP_DIAGNOSTIC_POP
0152 #undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
0153 
0154 } // namespace __locale
0155 _LIBCPP_END_NAMESPACE_STD
0156 
0157 #include <__locale_dir/support/no_locale/characters.h>
0158 #include <__locale_dir/support/no_locale/strtonum.h>
0159 
0160 #endif // _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H