2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
9 // The BSDs have lots of *_l functions. We don't want to define those symbols
10 // on other platforms though, for fear of conflicts with user code. So here,
11 // we will define the mapping from an internal macro to the real BSD symbol.
12 //===----------------------------------------------------------------------===//
14 #ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H
15 #define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H
20 #if _LIBCPP_HAS_WIDE_CHARACTERS
24 // <xlocale.h> must come after the includes above since the functions it includes depend on
25 // what headers have been included up to that point.
26 #if defined(__APPLE__) || defined(__FreeBSD__)
31 #include <__cstddef/size_t.h>
32 #include <__std_mbstate_t.h>
33 #include <__utility/forward.h>
35 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
36 # pragma GCC system_header
39 _LIBCPP_BEGIN_NAMESPACE_STD
41 inline _LIBCPP_HIDE_FROM_ABI
decltype(MB_CUR_MAX
) __libcpp_mb_cur_max_l(locale_t __loc
) { return MB_CUR_MAX_L(__loc
); }
43 #if _LIBCPP_HAS_WIDE_CHARACTERS
44 inline _LIBCPP_HIDE_FROM_ABI
wint_t __libcpp_btowc_l(int __c
, locale_t __loc
) { return ::btowc_l(__c
, __loc
); }
46 inline _LIBCPP_HIDE_FROM_ABI
int __libcpp_wctob_l(wint_t __c
, locale_t __loc
) { return ::wctob_l(__c
, __loc
); }
48 inline _LIBCPP_HIDE_FROM_ABI
size_t __libcpp_wcsnrtombs_l(
49 char* __dest
, const wchar_t** __src
, size_t __nwc
, size_t __len
, mbstate_t* __ps
, locale_t __loc
) {
50 return ::wcsnrtombs_l(__dest
, __src
, __nwc
, __len
, __ps
, __loc
);
53 inline _LIBCPP_HIDE_FROM_ABI
size_t __libcpp_wcrtomb_l(char* __s
, wchar_t __wc
, mbstate_t* __ps
, locale_t __loc
) {
54 return ::wcrtomb_l(__s
, __wc
, __ps
, __loc
);
57 inline _LIBCPP_HIDE_FROM_ABI
size_t __libcpp_mbsnrtowcs_l(
58 wchar_t* __dest
, const char** __src
, size_t __nms
, size_t __len
, mbstate_t* __ps
, locale_t __loc
) {
59 return ::mbsnrtowcs_l(__dest
, __src
, __nms
, __len
, __ps
, __loc
);
62 inline _LIBCPP_HIDE_FROM_ABI
size_t
63 __libcpp_mbrtowc_l(wchar_t* __pwc
, const char* __s
, size_t __n
, mbstate_t* __ps
, locale_t __loc
) {
64 return ::mbrtowc_l(__pwc
, __s
, __n
, __ps
, __loc
);
67 inline _LIBCPP_HIDE_FROM_ABI
int __libcpp_mbtowc_l(wchar_t* __pwc
, const char* __pmb
, size_t __max
, locale_t __loc
) {
68 return ::mbtowc_l(__pwc
, __pmb
, __max
, __loc
);
71 inline _LIBCPP_HIDE_FROM_ABI
size_t __libcpp_mbrlen_l(const char* __s
, size_t __n
, mbstate_t* __ps
, locale_t __loc
) {
72 return ::mbrlen_l(__s
, __n
, __ps
, __loc
);
74 #endif // _LIBCPP_HAS_WIDE_CHARACTERS
76 inline _LIBCPP_HIDE_FROM_ABI lconv
* __libcpp_localeconv_l(locale_t
& __loc
) { return ::localeconv_l(__loc
); }
78 #if _LIBCPP_HAS_WIDE_CHARACTERS
79 inline _LIBCPP_HIDE_FROM_ABI
size_t
80 __libcpp_mbsrtowcs_l(wchar_t* __dest
, const char** __src
, size_t __len
, mbstate_t* __ps
, locale_t __loc
) {
81 return ::mbsrtowcs_l(__dest
, __src
, __len
, __ps
, __loc
);
85 _LIBCPP_DIAGNOSTIC_PUSH
86 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
87 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
88 #ifdef _LIBCPP_COMPILER_CLANG_BASED
89 # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
91 # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
94 template <class... _Args
>
95 _LIBCPP_HIDE_FROM_ABI
_LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__
, 4, 5) int __libcpp_snprintf_l(
96 char* __s
, size_t __n
, locale_t __loc
, const char* __format
, _Args
&&... __args
) {
97 return ::snprintf_l(__s
, __n
, __loc
, __format
, std::forward
<_Args
>(__args
)...);
100 template <class... _Args
>
101 _LIBCPP_HIDE_FROM_ABI
_LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__
, 3, 4) int __libcpp_asprintf_l(
102 char** __s
, locale_t __loc
, const char* __format
, _Args
&&... __args
) {
103 return ::asprintf_l(__s
, __loc
, __format
, std::forward
<_Args
>(__args
)...);
106 template <class... _Args
>
107 _LIBCPP_HIDE_FROM_ABI
_LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__
, 3, 4) int __libcpp_sscanf_l(
108 const char* __s
, locale_t __loc
, const char* __format
, _Args
&&... __args
) {
109 return ::sscanf_l(__s
, __loc
, __format
, std::forward
<_Args
>(__args
)...);
111 _LIBCPP_DIAGNOSTIC_POP
112 #undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
114 _LIBCPP_END_NAMESPACE_STD
116 #endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H