Warning: This file is not a C or C++ file. It does not have highlighting.

1//===-----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
10#define _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
11
12#include <__config>
13#include <__utility/forward.h>
14#include <clocale> // uselocale & friends
15#include <cstdio>
16#include <cstdlib>
17#include <cwchar>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24namespace __locale {
25
26struct __locale_guard {
27 _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
28
29 _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
30 if (__old_loc_)
31 ::uselocale(__old_loc_);
32 }
33
34 locale_t __old_loc_;
35
36 __locale_guard(__locale_guard const&) = delete;
37 __locale_guard& operator=(__locale_guard const&) = delete;
38};
39
40//
41// Locale management
42//
43#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
44#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
45#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
46#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
47#define _LIBCPP_TIME_MASK LC_TIME_MASK
48#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
49#define _LIBCPP_ALL_MASK LC_ALL_MASK
50#define _LIBCPP_LC_ALL LC_ALL
51
52using __locale_t _LIBCPP_NODEBUG = locale_t;
53
54#if defined(_LIBCPP_BUILDING_LIBRARY)
55using __lconv_t _LIBCPP_NODEBUG = std::lconv;
56
57inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) {
58 return ::newlocale(__category_mask, __name, __loc);
59}
60
61inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
62
63inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) {
64 return ::setlocale(__category, __locale);
65}
66
67inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
68 __locale_guard __current(__loc);
69 return std::localeconv();
70}
71
72//
73// Other functions
74//
75inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) {
76 __locale_guard __current(__loc);
77 return MB_CUR_MAX;
78}
79# if _LIBCPP_HAS_WIDE_CHARACTERS
80inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) {
81 __locale_guard __current(__loc);
82 return std::btowc(__ch);
83}
84inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) {
85 __locale_guard __current(__loc);
86 return std::wctob(__ch);
87}
88inline _LIBCPP_HIDE_FROM_ABI size_t
89__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
90 __locale_guard __current(__loc);
91 return ::wcsnrtombs(__dest, __src, __nwc, __len, __ps); // non-standard
92}
93inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) {
94 __locale_guard __current(__loc);
95 return std::wcrtomb(__s, __ch, __ps);
96}
97inline _LIBCPP_HIDE_FROM_ABI size_t
98__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
99 __locale_guard __current(__loc);
100 return ::mbsnrtowcs(__dest, __src, __nms, __len, __ps); // non-standard
101}
102inline _LIBCPP_HIDE_FROM_ABI size_t
103__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
104 __locale_guard __current(__loc);
105 return std::mbrtowc(__pwc, __s, __n, __ps);
106}
107inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
108 __locale_guard __current(__loc);
109 return std::mbtowc(__pwc, __pmb, __max);
110}
111inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
112 __locale_guard __current(__loc);
113 return std::mbrlen(__s, __n, __ps);
114}
115inline _LIBCPP_HIDE_FROM_ABI size_t
116__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
117 __locale_guard __current(__loc);
118 return ::mbsrtowcs(__dest, __src, __len, __ps);
119}
120# endif // _LIBCPP_HAS_WIDE_CHARACTERS
121#endif // _LIBCPP_BUILDING_LIBRARY
122
123_LIBCPP_DIAGNOSTIC_PUSH
124_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
125_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
126#ifdef _LIBCPP_COMPILER_CLANG_BASED
127# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
128#else
129# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
130#endif
131
132template <class... _Args>
133_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
134 char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) {
135 __locale_guard __current(__loc);
136 return std::snprintf(__s, __n, __format, std::forward<_Args>(__args)...);
137}
138template <class... _Args>
139_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(
140 char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
141 __locale_guard __current(__loc);
142 return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard
143}
144template <class... _Args>
145_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
146 const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
147 __locale_guard __current(__loc);
148 return std::sscanf(__s, __format, std::forward<_Args>(__args)...);
149}
150
151_LIBCPP_DIAGNOSTIC_POP
152#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
153
154} // namespace __locale
155_LIBCPP_END_NAMESPACE_STD
156
157#include <__locale_dir/support/no_locale/characters.h>
158#include <__locale_dir/support/no_locale/strtonum.h>
159
160#endif // _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
161

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libcxx/include/__locale_dir/support/fuchsia.h