2016-03-09 23:39:39 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===---------------------- __bsd_locale_fallbacks.h ----------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-03-09 23:39:39 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// The BSDs have lots of *_l functions. This file provides reimplementations
|
|
|
|
// of those functions for non-BSD platforms.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
|
|
|
|
#define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2017-06-15 22:31:11 +08:00
|
|
|
#include <stdarg.h>
|
2016-03-09 23:39:39 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2017-08-03 10:50:43 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
|
|
|
#pragma GCC system_header
|
|
|
|
#endif
|
|
|
|
|
2016-03-09 23:39:39 +08:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return MB_CUR_MAX;
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
wint_t __libcpp_btowc_l(int __c, locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return btowc(__c);
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
int __libcpp_wctob_l(wint_t __c, locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return wctob(__c);
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
|
|
|
|
size_t __len, mbstate_t *__ps, locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return wcrtomb(__s, __wc, __ps);
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
|
|
|
|
size_t __len, mbstate_t *__ps, locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
|
|
|
|
mbstate_t *__ps, locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return mbrtowc(__pwc, __s, __n, __ps);
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return mbtowc(__pwc, __pmb, __max);
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return mbrlen(__s, __n, __ps);
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
lconv *__libcpp_localeconv_l(locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return localeconv();
|
|
|
|
}
|
|
|
|
|
2018-07-12 07:14:33 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2016-03-09 23:39:39 +08:00
|
|
|
size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
|
|
|
|
mbstate_t *__ps, locale_t __l)
|
|
|
|
{
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
return mbsrtowcs(__dest, __src, __len, __ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
|
|
|
|
va_list __va;
|
|
|
|
va_start(__va, __format);
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
int __res = vsnprintf(__s, __n, __format, __va);
|
|
|
|
va_end(__va);
|
|
|
|
return __res;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
|
|
|
|
va_list __va;
|
|
|
|
va_start(__va, __format);
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
int __res = vasprintf(__s, __format, __va);
|
|
|
|
va_end(__va);
|
|
|
|
return __res;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
|
|
|
|
va_list __va;
|
|
|
|
va_start(__va, __format);
|
2017-05-09 06:02:43 +08:00
|
|
|
__libcpp_locale_guard __current(__l);
|
2016-03-09 23:39:39 +08:00
|
|
|
int __res = vsscanf(__s, __format, __va);
|
|
|
|
va_end(__va);
|
|
|
|
return __res;
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
|