xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/libdruntime/core/stdc/wchar_.d (revision 0a3071956a3a9fdebdbf7f338cf2d439b45fc728)
1 /**
2  * D header file for C99.
3  *
4  * $(C_HEADER_DESCRIPTION pubs.opengroup.org/onlinepubs/009695399/basedefs/_wchar.h.html, _wchar.h)
5  *
6  * Copyright: Copyright Sean Kelly 2005 - 2009.
7  * License: Distributed under the
8  *      $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
9  *    (See accompanying file LICENSE)
10  * Authors:   Sean Kelly
11  * Source:    $(DRUNTIMESRC core/stdc/_wchar_.d)
12  * Standards: ISO/IEC 9899:1999 (E)
13  */
14 
15 module core.stdc.wchar_;
16 
17 import core.stdc.config;
18 import core.stdc.stdarg; // for va_list
19 import core.stdc.stdio;  // for FILE, not exposed per spec
20 public import core.stdc.stddef;  // for wchar_t
21 public import core.stdc.time;    // for tm
22 public import core.stdc.stdint;  // for WCHAR_MIN, WCHAR_MAX
23 
24 extern (C):
25 @system:
26 nothrow:
27 @nogc:
28 
version(CRuntime_Glibc)29 version (CRuntime_Glibc)
30 {
31     ///
32     struct mbstate_t
33     {
34         int __count;
35         union ___value
36         {
37             wint_t __wch = 0;
38             char[4] __wchb;
39         }
40         ___value __value;
41     }
42 }
43 else version (FreeBSD)
44 {
45     ///
46     union __mbstate_t // <sys/_types.h>
47     {
48         char[128]   _mbstate8 = 0;
49         long        _mbstateL;
50     }
51 
52     ///
53     alias mbstate_t = __mbstate_t;
54 }
55 else version (NetBSD)
56 {
57     ///
58     union __mbstate_t
59     {
60         int64_t   __mbstateL;
61         char[128] __mbstate8;
62     }
63 
64     ///
65     alias mbstate_t = __mbstate_t;
66 }
67 else version (OpenBSD)
68 {
69     ///
70     union __mbstate_t
71     {
72         char[128] __mbstate8 = 0;
73         int64_t   __mbstateL;
74     }
75 
76     ///
77     alias mbstate_t = __mbstate_t;
78 }
79 else version (DragonFlyBSD)
80 {
81     ///
82     union __mbstate_t                   // <sys/stdint.h>
83     {
84         char[128]   _mbstate8 = 0;
85         long        _mbstateL;
86     }
87 
88     ///
89     alias mbstate_t = __mbstate_t;
90 }
91 else version (Solaris)
92 {
93     ///
94     struct __mbstate_t
95     {
96         version (D_LP64)
97         {
98             long[4] __filler;
99         }
100         else
101         {
102             int[6] __filler;
103         }
104     }
105 
106     ///
107     alias mbstate_t = __mbstate_t;
108 }
109 else version (CRuntime_UClibc)
110 {
111     ///
112     struct mbstate_t
113     {
114         wchar_t __mask = 0;
115         wchar_t __wc = 0;
116     }
117 }
118 else
119 {
120     ///
121     alias int mbstate_t;
122 }
123 
124 ///
125 alias wchar_t wint_t;
126 
127 ///
128 enum wchar_t WEOF = 0xFFFF;
129 
130 ///
131 int fwprintf(FILE* stream, const scope wchar_t* format, scope const ...);
132 ///
133 int fwscanf(FILE* stream, const scope wchar_t* format, scope ...);
134 ///
135 int swprintf(wchar_t* s, size_t n, const scope wchar_t* format, scope const ...);
136 ///
137 int swscanf(const scope wchar_t* s, const scope wchar_t* format, scope ...);
138 ///
139 int vfwprintf(FILE* stream, const scope wchar_t* format, va_list arg);
140 ///
141 int vfwscanf(FILE* stream, const scope wchar_t* format, va_list arg);
142 ///
143 int vswprintf(wchar_t* s, size_t n, const scope wchar_t* format, va_list arg);
144 ///
145 int vswscanf(const scope wchar_t* s, const scope wchar_t* format, va_list arg);
146 ///
147 int vwprintf(const scope wchar_t* format, va_list arg);
148 ///
149 int vwscanf(const scope wchar_t* format, va_list arg);
150 ///
151 int wprintf(const scope wchar_t* format, scope const ...);
152 ///
153 int wscanf(const scope wchar_t* format, scope ...);
154 
155 // No unsafe pointer manipulation.
156 @trusted
157 {
158     ///
159     wint_t fgetwc(FILE* stream);
160     ///
161     wint_t fputwc(wchar_t c, FILE* stream);
162 }
163 
164 ///
165 wchar_t* fgetws(wchar_t* s, int n, FILE* stream);
166 ///
167 int      fputws(const scope wchar_t* s, FILE* stream);
168 
169 // No unsafe pointer manipulation.
170 extern (D) @trusted
171 {
172     ///
173     wint_t getwchar()                     { return fgetwc(stdin);     }
174     ///
175     wint_t putwchar(wchar_t c)            { return fputwc(c,stdout);  }
176 }
177 
178 ///
179 alias getwc = fgetwc;
180 ///
181 alias putwc = fputwc;
182 
183 // No unsafe pointer manipulation.
184 @trusted
185 {
186     ///
187     wint_t ungetwc(wint_t c, FILE* stream);
188     ///
189     version (CRuntime_Microsoft)
190     {
191         // MSVC defines this as an inline function.
192         int fwide(FILE* stream, int mode) { return mode; }
193     }
194     else
195     {
196         int    fwide(FILE* stream, int mode);
197     }
198 }
199 
200 ///
201 double  wcstod(const scope wchar_t* nptr, wchar_t** endptr);
202 ///
203 float   wcstof(const scope wchar_t* nptr, wchar_t** endptr);
204 ///
205 real    wcstold(const scope wchar_t* nptr, wchar_t** endptr);
206 ///
207 c_long  wcstol(const scope wchar_t* nptr, wchar_t** endptr, int base);
208 ///
209 long    wcstoll(const scope wchar_t* nptr, wchar_t** endptr, int base);
210 ///
211 c_ulong wcstoul(const scope wchar_t* nptr, wchar_t** endptr, int base);
212 ///
213 ulong   wcstoull(const scope wchar_t* nptr, wchar_t** endptr, int base);
214 
215 ///
216 pure wchar_t* wcscpy(return scope wchar_t* s1, scope const wchar_t* s2);
217 ///
218 pure wchar_t* wcsncpy(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
219 ///
220 pure wchar_t* wcscat(return scope wchar_t* s1, scope const wchar_t* s2);
221 ///
222 pure wchar_t* wcsncat(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
223 ///
224 pure int wcscmp(scope const wchar_t* s1, scope const wchar_t* s2);
225 ///
226 int      wcscoll(scope const wchar_t* s1, scope const wchar_t* s2);
227 ///
228 pure int wcsncmp(scope const wchar_t* s1, scope const wchar_t* s2, size_t n);
229 ///
230 size_t   wcsxfrm(scope wchar_t* s1, scope const wchar_t* s2, size_t n);
231 ///
232 pure inout(wchar_t)* wcschr(return scope inout(wchar_t)* s, wchar_t c);
233 ///
234 pure size_t wcscspn(scope const wchar_t* s1, scope const wchar_t* s2);
235 ///
236 pure inout(wchar_t)* wcspbrk(return scope inout(wchar_t)* s1, scope const wchar_t* s2);
237 ///
238 pure inout(wchar_t)* wcsrchr(return scope inout(wchar_t)* s, wchar_t c);
239 ///
240 pure size_t wcsspn(scope const wchar_t* s1, scope const wchar_t* s2);
241 ///
242 pure inout(wchar_t)* wcsstr(return scope inout(wchar_t)* s1, scope const wchar_t* s2);
243 ///
244 wchar_t* wcstok(return scope wchar_t* s1, scope const wchar_t* s2, wchar_t** ptr);
245 ///
246 pure size_t wcslen(scope const wchar_t* s);
247 
248 ///
249 pure inout(wchar_t)* wmemchr(return scope inout wchar_t* s, wchar_t c, size_t n);
250 ///
251 pure int      wmemcmp(scope const wchar_t* s1, scope const wchar_t* s2, size_t n);
252 ///
253 pure wchar_t* wmemcpy(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
254 ///
255 pure wchar_t* wmemmove(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
256 ///
257 pure wchar_t* wmemset(return scope wchar_t* s, wchar_t c, size_t n);
258 
259 ///
260 size_t wcsftime(wchar_t* s, size_t maxsize, const scope wchar_t* format, const scope tm* timeptr);
261 
262 version (Windows)
263 {
264     ///
265     wchar_t* _wasctime(tm*);      // non-standard
266     ///
267     wchar_t* _wctime(time_t*);    // non-standard
268     ///
269     wchar_t* _wstrdate(wchar_t*); // non-standard
270     ///
271     wchar_t* _wstrtime(wchar_t*); // non-standard
272 }
273 
274 // No unsafe pointer manipulation.
275 @trusted
276 {
277     ///
278     wint_t btowc(int c);
279     ///
280     int    wctob(wint_t c);
281 }
282 
283 ///
284 int    mbsinit(const scope mbstate_t* ps);
285 ///
286 size_t mbrlen(const scope char* s, size_t n, mbstate_t* ps);
287 ///
288 size_t mbrtowc(wchar_t* pwc, const scope char* s, size_t n, mbstate_t* ps);
289 ///
290 size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps);
291 ///
292 size_t mbsrtowcs(wchar_t* dst, const scope char** src, size_t len, mbstate_t* ps);
293 ///
294 size_t wcsrtombs(char* dst, const scope wchar_t** src, size_t len, mbstate_t* ps);
295