libstdc++
cwchar
Go to the documentation of this file.
1// -*- C++ -*- forwarding header.
2
3// Copyright (C) 1997-2025 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file include/cwchar
26 * This is a Standard C++ Library file. You should @c \#include this file
27 * in your programs, rather than any of the @a *.h implementation files.
28 *
29 * This is the C++ version of the Standard C Library header @c wchar.h,
30 * and its contents are (mostly) the same as that header, but are all
31 * contained in the namespace @c std (except for names which are defined
32 * as macros in C).
33 */
34
35//
36// ISO C++ 14882: 21.4
37//
38
39#ifndef _GLIBCXX_CWCHAR
40#define _GLIBCXX_CWCHAR 1
41
42#ifdef _GLIBCXX_SYSHDR
43#pragma GCC system_header
44#endif
45
46#include <bits/c++config.h>
47
48#if _GLIBCXX_HAVE_WCHAR_H
49#include <wchar.h>
50#endif
51
52// Need to do a bit of trickery here with mbstate_t as char_traits
53// assumes it is in wchar.h, regardless of wchar_t specializations.
54#ifndef _GLIBCXX_HAVE_MBSTATE_T
55extern "C"
56{
57 typedef struct
58 {
59 int __fill[6];
60 } mbstate_t;
61}
62#endif
63
64namespace std
65{
66 using ::mbstate_t;
67} // namespace std
68
69// Get rid of those macros defined in <wchar.h> in lieu of real functions.
70#undef btowc
71#undef fgetwc
72#undef fgetws
73#undef fputwc
74#undef fputws
75#undef fwide
76#undef fwprintf
77#undef fwscanf
78#undef getwc
79#undef getwchar
80#undef mbrlen
81#undef mbrtowc
82#undef mbsinit
83#undef mbsrtowcs
84#undef putwc
85#undef putwchar
86#undef swprintf
87#undef swscanf
88#undef ungetwc
89#undef vfwprintf
90#if _GLIBCXX_HAVE_VFWSCANF
91# undef vfwscanf
92#endif
93#undef vswprintf
94#if _GLIBCXX_HAVE_VSWSCANF
95# undef vswscanf
96#endif
97#undef vwprintf
98#if _GLIBCXX_HAVE_VWSCANF
99# undef vwscanf
100#endif
101#undef wcrtomb
102#undef wcscat
103#undef wcschr
104#undef wcscmp
105#undef wcscoll
106#undef wcscpy
107#undef wcscspn
108#undef wcsftime
109#undef wcslen
110#undef wcsncat
111#undef wcsncmp
112#undef wcsncpy
113#undef wcspbrk
114#undef wcsrchr
115#undef wcsrtombs
116#undef wcsspn
117#undef wcsstr
118#undef wcstod
119#if _GLIBCXX_HAVE_WCSTOF
120# undef wcstof
121#endif
122#undef wcstok
123#undef wcstol
124#undef wcstoul
125#undef wcsxfrm
126#undef wctob
127#undef wmemchr
128#undef wmemcmp
129#undef wmemcpy
130#undef wmemmove
131#undef wmemset
132#undef wprintf
133#undef wscanf
134
135#if _GLIBCXX_USE_WCHAR_T
136
137extern "C++"
138{
139namespace std _GLIBCXX_VISIBILITY(default)
140{
141_GLIBCXX_BEGIN_NAMESPACE_VERSION
142
143 using ::wint_t;
144
145 using ::btowc;
146 using ::fgetwc;
147 using ::fgetws;
148 using ::fputwc;
149 using ::fputws;
150 using ::fwide;
151 using ::fwprintf;
152 using ::fwscanf;
153 using ::getwc;
154 using ::getwchar;
155 using ::mbrlen;
156 using ::mbrtowc;
157 using ::mbsinit;
158 using ::mbsrtowcs;
159 using ::putwc;
160 using ::putwchar;
161#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
162 using ::swprintf;
163#endif
164 using ::swscanf;
165 using ::ungetwc;
166 using ::vfwprintf;
167#if _GLIBCXX_HAVE_VFWSCANF
168 using ::vfwscanf;
169#endif
170#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
171 using ::vswprintf;
172#endif
173#if _GLIBCXX_HAVE_VSWSCANF
174 using ::vswscanf;
175#endif
176 using ::vwprintf;
177#if _GLIBCXX_HAVE_VWSCANF
178 using ::vwscanf;
179#endif
180 using ::wcrtomb;
181 using ::wcscat;
182 using ::wcscmp;
183 using ::wcscoll;
184 using ::wcscpy;
185 using ::wcscspn;
186 using ::wcsftime;
187 using ::wcslen;
188 using ::wcsncat;
189 using ::wcsncmp;
190 using ::wcsncpy;
191 using ::wcsrtombs;
192 using ::wcsspn;
193 using ::wcstod;
194#if _GLIBCXX_HAVE_WCSTOF
195 using ::wcstof;
196#endif
197 using ::wcstok;
198 using ::wcstol;
199 using ::wcstoul;
200 using ::wcsxfrm;
201 using ::wctob;
202 using ::wmemcmp;
203 using ::wmemcpy;
204 using ::wmemmove;
205 using ::wmemset;
206 using ::wprintf;
207 using ::wscanf;
208 using ::wcschr;
209 using ::wcspbrk;
210 using ::wcsrchr;
211 using ::wcsstr;
212 using ::wmemchr;
213
214#ifndef __CORRECT_ISO_CPP_WCHAR_H_PROTO
215 inline wchar_t*
216 wcschr(wchar_t* __p, wchar_t __c)
217 { return wcschr(const_cast<const wchar_t*>(__p), __c); }
218
219 inline wchar_t*
220 wcspbrk(wchar_t* __s1, const wchar_t* __s2)
221 { return wcspbrk(const_cast<const wchar_t*>(__s1), __s2); }
222
223 inline wchar_t*
224 wcsrchr(wchar_t* __p, wchar_t __c)
225 { return wcsrchr(const_cast<const wchar_t*>(__p), __c); }
226
227 inline wchar_t*
228 wcsstr(wchar_t* __s1, const wchar_t* __s2)
229 { return wcsstr(const_cast<const wchar_t*>(__s1), __s2); }
230
231 inline wchar_t*
232 wmemchr(wchar_t* __p, wchar_t __c, size_t __n)
233 { return wmemchr(const_cast<const wchar_t*>(__p), __c, __n); }
234#endif
235
236_GLIBCXX_END_NAMESPACE_VERSION
237} // namespace
238} // extern "C++"
239
240#if _GLIBCXX_USE_C99_WCHAR
241
242#undef wcstold
243#undef wcstoll
244#undef wcstoull
245
246namespace __gnu_cxx
247{
248#if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
249 extern "C" long double
250 (wcstold)(const wchar_t * __restrict, wchar_t ** __restrict) throw ();
251#endif
252#if !_GLIBCXX_USE_C99_DYNAMIC
253 using ::wcstold;
254#endif
255#if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
256 extern "C" long long int
257 (wcstoll)(const wchar_t * __restrict, wchar_t ** __restrict, int) throw ();
258 extern "C" unsigned long long int
259 (wcstoull)(const wchar_t * __restrict, wchar_t ** __restrict, int) throw ();
260#endif
261#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
262 using ::wcstoll;
263 using ::wcstoull;
264#endif
265} // namespace __gnu_cxx
266
267namespace std
268{
269 using ::__gnu_cxx::wcstold;
270 using ::__gnu_cxx::wcstoll;
271 using ::__gnu_cxx::wcstoull;
272} // namespace
273
274#endif
275
276#endif //_GLIBCXX_USE_WCHAR_T
277
278#if __cplusplus >= 201103L
279
280#ifdef _GLIBCXX_USE_WCHAR_T
281
282namespace std
283{
284#if _GLIBCXX_HAVE_WCSTOF
285 using std::wcstof;
286#endif
287#if _GLIBCXX_HAVE_VFWSCANF
288 using std::vfwscanf;
289#endif
290#if _GLIBCXX_HAVE_VSWSCANF
291 using std::vswscanf;
292#endif
293#if _GLIBCXX_HAVE_VWSCANF
294 using std::vwscanf;
295#endif
296
297#if _GLIBCXX_USE_C99_WCHAR
298 using std::wcstold;
299 using std::wcstoll;
300 using std::wcstoull;
301#endif
302} // namespace
303
304#endif // _GLIBCXX_USE_WCHAR_T
305
306#endif // C++11
307
308#endif