Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 // The BSDs have lots of *_l functions.  This file provides reimplementations
0010 // of those functions for non-BSD platforms.
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H
0014 #define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H
0015 
0016 #include <locale.h>
0017 #include <stdarg.h>
0018 #include <stdio.h>
0019 #include <stdlib.h>
0020 
0021 #if _LIBCPP_HAS_WIDE_CHARACTERS
0022 #  include <cwchar>
0023 #endif
0024 
0025 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0026 #  pragma GCC system_header
0027 #endif
0028 
0029 _LIBCPP_BEGIN_NAMESPACE_STD
0030 
0031 struct __locale_guard {
0032   _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
0033 
0034   _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
0035     if (__old_loc_)
0036       ::uselocale(__old_loc_);
0037   }
0038 
0039   locale_t __old_loc_;
0040 
0041   __locale_guard(__locale_guard const&)            = delete;
0042   __locale_guard& operator=(__locale_guard const&) = delete;
0043 };
0044 
0045 inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) {
0046   __locale_guard __current(__l);
0047   return MB_CUR_MAX;
0048 }
0049 
0050 #if _LIBCPP_HAS_WIDE_CHARACTERS
0051 inline _LIBCPP_HIDE_FROM_ABI wint_t __libcpp_btowc_l(int __c, locale_t __l) {
0052   __locale_guard __current(__l);
0053   return btowc(__c);
0054 }
0055 
0056 inline _LIBCPP_HIDE_FROM_ABI int __libcpp_wctob_l(wint_t __c, locale_t __l) {
0057   __locale_guard __current(__l);
0058   return wctob(__c);
0059 }
0060 
0061 inline _LIBCPP_HIDE_FROM_ABI size_t
0062 __libcpp_wcsnrtombs_l(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, locale_t __l) {
0063   __locale_guard __current(__l);
0064   return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
0065 }
0066 
0067 inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcrtomb_l(char* __s, wchar_t __wc, mbstate_t* __ps, locale_t __l) {
0068   __locale_guard __current(__l);
0069   return wcrtomb(__s, __wc, __ps);
0070 }
0071 
0072 inline _LIBCPP_HIDE_FROM_ABI size_t
0073 __libcpp_mbsnrtowcs_l(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, locale_t __l) {
0074   __locale_guard __current(__l);
0075   return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
0076 }
0077 
0078 inline _LIBCPP_HIDE_FROM_ABI size_t
0079 __libcpp_mbrtowc_l(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
0080   __locale_guard __current(__l);
0081   return mbrtowc(__pwc, __s, __n, __ps);
0082 }
0083 
0084 inline _LIBCPP_HIDE_FROM_ABI int __libcpp_mbtowc_l(wchar_t* __pwc, const char* __pmb, size_t __max, locale_t __l) {
0085   __locale_guard __current(__l);
0086   return mbtowc(__pwc, __pmb, __max);
0087 }
0088 
0089 inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbrlen_l(const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
0090   __locale_guard __current(__l);
0091   return mbrlen(__s, __n, __ps);
0092 }
0093 #endif // _LIBCPP_HAS_WIDE_CHARACTERS
0094 
0095 inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(locale_t& __l) {
0096   __locale_guard __current(__l);
0097   return localeconv();
0098 }
0099 
0100 #if _LIBCPP_HAS_WIDE_CHARACTERS
0101 inline _LIBCPP_HIDE_FROM_ABI size_t
0102 __libcpp_mbsrtowcs_l(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, locale_t __l) {
0103   __locale_guard __current(__l);
0104   return mbsrtowcs(__dest, __src, __len, __ps);
0105 }
0106 #endif
0107 
0108 inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __libcpp_snprintf_l(
0109     char* __s, size_t __n, locale_t __l, const char* __format, ...) {
0110   va_list __va;
0111   va_start(__va, __format);
0112   __locale_guard __current(__l);
0113   int __res = vsnprintf(__s, __n, __format, __va);
0114   va_end(__va);
0115   return __res;
0116 }
0117 
0118 inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l(
0119     char** __s, locale_t __l, const char* __format, ...) {
0120   va_list __va;
0121   va_start(__va, __format);
0122   __locale_guard __current(__l);
0123   int __res = vasprintf(__s, __format, __va);
0124   va_end(__va);
0125   return __res;
0126 }
0127 
0128 inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l(
0129     const char* __s, locale_t __l, const char* __format, ...) {
0130   va_list __va;
0131   va_start(__va, __format);
0132   __locale_guard __current(__l);
0133   int __res = vsscanf(__s, __format, __va);
0134   va_end(__va);
0135   return __res;
0136 }
0137 
0138 _LIBCPP_END_NAMESPACE_STD
0139 
0140 #endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H