1d82bf10dim// -*- C++ -*-
2d82bf10dim//===---------------------- __bsd_locale_fallbacks.h ----------------------===//
3d82bf10dim//
410907fcdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
510907fcdim// See https://llvm.org/LICENSE.txt for license information.
610907fcdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7d82bf10dim//
8d82bf10dim//===----------------------------------------------------------------------===//
9d82bf10dim// The BSDs have lots of *_l functions.  This file provides reimplementations
10d82bf10dim// of those functions for non-BSD platforms.
11d82bf10dim//===----------------------------------------------------------------------===//
12d82bf10dim
13d82bf10dim#ifndef _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
14d82bf10dim#define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
15d82bf10dim
16d82bf10dim#include <stdlib.h>
1737ec3a3dim#include <stdarg.h>
18d82bf10dim#include <memory>
19d82bf10dim
202a0754adim#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
212a0754adim#pragma GCC system_header
222a0754adim#endif
232a0754adim
24d82bf10dim_LIBCPP_BEGIN_NAMESPACE_STD
25d82bf10dim
26bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
27d82bf10dimdecltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
28d82bf10dim{
29caee8aedim    __libcpp_locale_guard __current(__l);
30d82bf10dim    return MB_CUR_MAX;
31d82bf10dim}
32d82bf10dim
33bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
34d82bf10dimwint_t __libcpp_btowc_l(int __c, locale_t __l)
35d82bf10dim{
36caee8aedim    __libcpp_locale_guard __current(__l);
37d82bf10dim    return btowc(__c);
38d82bf10dim}
39d82bf10dim
40bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
41d82bf10dimint __libcpp_wctob_l(wint_t __c, locale_t __l)
42d82bf10dim{
43caee8aedim    __libcpp_locale_guard __current(__l);
44d82bf10dim    return wctob(__c);
45d82bf10dim}
46d82bf10dim
47bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
48d82bf10dimsize_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
49d82bf10dim                         size_t __len, mbstate_t *__ps, locale_t __l)
50d82bf10dim{
51caee8aedim    __libcpp_locale_guard __current(__l);
52d82bf10dim    return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
53d82bf10dim}
54d82bf10dim
55bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
56d82bf10dimsize_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
57d82bf10dim{
58caee8aedim    __libcpp_locale_guard __current(__l);
59d82bf10dim    return wcrtomb(__s, __wc, __ps);
60d82bf10dim}
61d82bf10dim
62bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
63d82bf10dimsize_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
64d82bf10dim                      size_t __len, mbstate_t *__ps, locale_t __l)
65d82bf10dim{
66caee8aedim    __libcpp_locale_guard __current(__l);
67d82bf10dim    return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
68d82bf10dim}
69d82bf10dim
70bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
71d82bf10dimsize_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
72d82bf10dim                   mbstate_t *__ps, locale_t __l)
73d82bf10dim{
74caee8aedim    __libcpp_locale_guard __current(__l);
75d82bf10dim    return mbrtowc(__pwc, __s, __n, __ps);
76d82bf10dim}
77d82bf10dim
78bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
79d82bf10dimint __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l)
80d82bf10dim{
81caee8aedim    __libcpp_locale_guard __current(__l);
82d82bf10dim    return mbtowc(__pwc, __pmb, __max);
83d82bf10dim}
84d82bf10dim
85bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
86d82bf10dimsize_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l)
87d82bf10dim{
88caee8aedim    __libcpp_locale_guard __current(__l);
89d82bf10dim    return mbrlen(__s, __n, __ps);
90d82bf10dim}
91d82bf10dim
92bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
93d82bf10dimlconv *__libcpp_localeconv_l(locale_t __l)
94d82bf10dim{
95caee8aedim    __libcpp_locale_guard __current(__l);
96d82bf10dim    return localeconv();
97d82bf10dim}
98d82bf10dim
99bd3d2f4diminline _LIBCPP_INLINE_VISIBILITY
100d82bf10dimsize_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
101d82bf10dim                     mbstate_t *__ps, locale_t __l)
102d82bf10dim{
103caee8aedim    __libcpp_locale_guard __current(__l);
104d82bf10dim    return mbsrtowcs(__dest, __src, __len, __ps);
105d82bf10dim}
106d82bf10dim
107d82bf10diminline
108d82bf10dimint __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
109d82bf10dim    va_list __va;
110d82bf10dim    va_start(__va, __format);
111caee8aedim    __libcpp_locale_guard __current(__l);
112d82bf10dim    int __res = vsnprintf(__s, __n, __format, __va);
113d82bf10dim    va_end(__va);
114d82bf10dim    return __res;
115d82bf10dim}
116d82bf10dim
117d82bf10diminline
118d82bf10dimint __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
119d82bf10dim    va_list __va;
120d82bf10dim    va_start(__va, __format);
121caee8aedim    __libcpp_locale_guard __current(__l);
122d82bf10dim    int __res = vasprintf(__s, __format, __va);
123d82bf10dim    va_end(__va);
124d82bf10dim    return __res;
125d82bf10dim}
126d82bf10dim
127d82bf10diminline
128d82bf10dimint __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
129d82bf10dim    va_list __va;
130d82bf10dim    va_start(__va, __format);
131caee8aedim    __libcpp_locale_guard __current(__l);
132d82bf10dim    int __res = vsscanf(__s, __format, __va);
133d82bf10dim    va_end(__va);
134d82bf10dim    return __res;
135d82bf10dim}
136d82bf10dim
137d82bf10dim_LIBCPP_END_NAMESPACE_STD
138d82bf10dim
139d82bf10dim#endif // _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
140