HowToReleaseLLVM: Add description of the bug triage process
[llvm-project.git] / libcxx / include / __bsd_locale_fallbacks.h
blob3d5b78574480564a4d0ff01405fab8d8241bf74f
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
9 // The BSDs have lots of *_l functions. This file provides reimplementations
10 // of those functions for non-BSD platforms.
11 //===----------------------------------------------------------------------===//
13 #ifndef _LIBCPP___BSD_LOCALE_FALLBACKS_H
14 #define _LIBCPP___BSD_LOCALE_FALLBACKS_H
16 #include <memory>
17 #include <stdarg.h>
18 #include <stdlib.h>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 # pragma GCC system_header
22 #endif
24 _LIBCPP_BEGIN_NAMESPACE_STD
26 inline _LIBCPP_INLINE_VISIBILITY
27 decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
29 __libcpp_locale_guard __current(__l);
30 return MB_CUR_MAX;
33 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
34 inline _LIBCPP_INLINE_VISIBILITY
35 wint_t __libcpp_btowc_l(int __c, locale_t __l)
37 __libcpp_locale_guard __current(__l);
38 return btowc(__c);
41 inline _LIBCPP_INLINE_VISIBILITY
42 int __libcpp_wctob_l(wint_t __c, locale_t __l)
44 __libcpp_locale_guard __current(__l);
45 return wctob(__c);
48 inline _LIBCPP_INLINE_VISIBILITY
49 size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
50 size_t __len, mbstate_t *__ps, locale_t __l)
52 __libcpp_locale_guard __current(__l);
53 return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
56 inline _LIBCPP_INLINE_VISIBILITY
57 size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
59 __libcpp_locale_guard __current(__l);
60 return wcrtomb(__s, __wc, __ps);
63 inline _LIBCPP_INLINE_VISIBILITY
64 size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
65 size_t __len, mbstate_t *__ps, locale_t __l)
67 __libcpp_locale_guard __current(__l);
68 return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
71 inline _LIBCPP_INLINE_VISIBILITY
72 size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
73 mbstate_t *__ps, locale_t __l)
75 __libcpp_locale_guard __current(__l);
76 return mbrtowc(__pwc, __s, __n, __ps);
79 inline _LIBCPP_INLINE_VISIBILITY
80 int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l)
82 __libcpp_locale_guard __current(__l);
83 return mbtowc(__pwc, __pmb, __max);
86 inline _LIBCPP_INLINE_VISIBILITY
87 size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l)
89 __libcpp_locale_guard __current(__l);
90 return mbrlen(__s, __n, __ps);
92 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
94 inline _LIBCPP_INLINE_VISIBILITY
95 lconv *__libcpp_localeconv_l(locale_t __l)
97 __libcpp_locale_guard __current(__l);
98 return localeconv();
101 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
102 inline _LIBCPP_INLINE_VISIBILITY
103 size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
104 mbstate_t *__ps, locale_t __l)
106 __libcpp_locale_guard __current(__l);
107 return mbsrtowcs(__dest, __src, __len, __ps);
109 #endif
111 inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5)
112 int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
113 va_list __va;
114 va_start(__va, __format);
115 __libcpp_locale_guard __current(__l);
116 int __res = vsnprintf(__s, __n, __format, __va);
117 va_end(__va);
118 return __res;
121 inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
122 int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
123 va_list __va;
124 va_start(__va, __format);
125 __libcpp_locale_guard __current(__l);
126 int __res = vasprintf(__s, __format, __va);
127 va_end(__va);
128 return __res;
131 inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4)
132 int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
133 va_list __va;
134 va_start(__va, __format);
135 __libcpp_locale_guard __current(__l);
136 int __res = vsscanf(__s, __format, __va);
137 va_end(__va);
138 return __res;
141 _LIBCPP_END_NAMESPACE_STD
143 #endif // _LIBCPP___BSD_LOCALE_FALLBACKS_H