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 nothrow:
26 @nogc:
27 
28 version (CRuntime_Glibc)
29 {
30     ///
31     struct mbstate_t
32     {
33         int __count;
34         union ___value
35         {
36             wint_t __wch = 0;
37             char[4] __wchb;
38         }
39         ___value __value;
40     }
41 }
42 else version (FreeBSD)
43 {
44     ///
45     union __mbstate_t // <sys/_types.h>
46     {
47         char[128]   _mbstate8 = 0;
48         long        _mbstateL;
49     }
50 
51     ///
52     alias mbstate_t = __mbstate_t;
53 }
54 else version (NetBSD)
55 {
56     ///
57     union __mbstate_t
58     {
59         int64_t   __mbstateL;
60         char[128] __mbstate8;
61     }
62 
63     ///
64     alias mbstate_t = __mbstate_t;
65 }
66 else version (OpenBSD)
67 {
68     ///
69     union __mbstate_t
70     {
71         char[128] __mbstate8 = 0;
72         int64_t   __mbstateL;
73     }
74 
75     ///
76     alias mbstate_t = __mbstate_t;
77 }
78 else version (DragonFlyBSD)
79 {
80     ///
81     union __mbstate_t                   // <sys/stdint.h>
82     {
83         char[128]   _mbstate8 = 0;
84         long        _mbstateL;
85     }
86 
87     ///
88     alias mbstate_t = __mbstate_t;
89 }
90 else version (Solaris)
91 {
92     ///
93     struct __mbstate_t
94     {
95         version (D_LP64)
96         {
97             long[4] __filler;
98         }
99         else
100         {
101             int[6] __filler;
102         }
103     }
104 
105     ///
106     alias mbstate_t = __mbstate_t;
107 }
108 else version (CRuntime_UClibc)
109 {
110     ///
111     struct mbstate_t
112     {
113         wchar_t __mask = 0;
114         wchar_t __wc = 0;
115     }
116 }
117 else
118 {
119     ///
120     alias int mbstate_t;
121 }
122 
123 ///
124 alias wchar_t wint_t;
125 
126 ///
127 enum wchar_t WEOF = 0xFFFF;
128 
129 version (CRuntime_Glibc)
130 {
131     ///
132     int fwprintf(FILE* stream, const scope wchar_t* format, scope const ...);
133     ///
134     int __isoc99_fwscanf(FILE* stream, const scope wchar_t* format, scope ...);
135     ///
136     alias fwscanf = __isoc99_fwscanf;
137     ///
138     int swprintf(wchar_t* s, size_t n, const scope wchar_t* format, scope const ...);
139     ///
140     int __isoc99_swscanf(const scope wchar_t* s, const scope wchar_t* format, scope ...);
141     ///
142     alias swscanf = __isoc99_swscanf;
143     ///
144     int vfwprintf(FILE* stream, const scope wchar_t* format, va_list arg);
145     ///
146     int __isoc99_vfwscanf(FILE* stream, const scope wchar_t* format, va_list arg);
147     ///
148     alias vfwscanf = __isoc99_vfwscanf;
149     ///
150     int vswprintf(wchar_t* s, size_t n, const scope wchar_t* format, va_list arg);
151     ///
152     int __isoc99_vswscanf(const scope wchar_t* s, const scope wchar_t* format, va_list arg);
153     ///
154     alias vswscanf = __isoc99_vswscanf;
155     ///
156     int vwprintf(const scope wchar_t* format, va_list arg);
157     ///
158     int __isoc99_vwscanf(const scope wchar_t* format, va_list arg);
159     ///
160     alias vwscanf = __isoc99_vwscanf;
161     ///
162     int wprintf(const scope wchar_t* format, scope const ...);
163     ///
164     int __isoc99_wscanf(const scope wchar_t* format, scope ...);
165     ///
166     alias wscanf = __isoc99_wscanf;
167 }
168 else
169 {
170     ///
171     int fwprintf(FILE* stream, const scope wchar_t* format, scope const ...);
172     ///
173     int fwscanf(FILE* stream, const scope wchar_t* format, scope ...);
174     ///
175     int swprintf(wchar_t* s, size_t n, const scope wchar_t* format, scope const ...);
176     ///
177     int swscanf(const scope wchar_t* s, const scope wchar_t* format, scope ...);
178     ///
179     int vfwprintf(FILE* stream, const scope wchar_t* format, va_list arg);
180     ///
181     int vfwscanf(FILE* stream, const scope wchar_t* format, va_list arg);
182     ///
183     int vswprintf(wchar_t* s, size_t n, const scope wchar_t* format, va_list arg);
184     ///
185     int vswscanf(const scope wchar_t* s, const scope wchar_t* format, va_list arg);
186     ///
187     int vwprintf(const scope wchar_t* format, va_list arg);
188     ///
189     int vwscanf(const scope wchar_t* format, va_list arg);
190     ///
191     int wprintf(const scope wchar_t* format, scope const ...);
192     ///
193     int wscanf(const scope wchar_t* format, scope ...);
194 }
195 
196 // No unsafe pointer manipulation.
197 @trusted
198 {
199     ///
200     wint_t fgetwc(FILE* stream);
201     ///
202     wint_t fputwc(wchar_t c, FILE* stream);
203 }
204 
205 ///
206 wchar_t* fgetws(wchar_t* s, int n, FILE* stream);
207 ///
208 int      fputws(const scope wchar_t* s, FILE* stream);
209 
210 // No unsafe pointer manipulation.
211 extern (D) @trusted
212 {
213     ///
214     wint_t getwchar()                     { return fgetwc(stdin);     }
215     ///
216     wint_t putwchar(wchar_t c)            { return fputwc(c,stdout);  }
217 }
218 
219 ///
220 alias getwc = fgetwc;
221 ///
222 alias putwc = fputwc;
223 
224 // No unsafe pointer manipulation.
225 @trusted
226 {
227     ///
228     wint_t ungetwc(wint_t c, FILE* stream);
229     ///
230     version (CRuntime_Microsoft)
231     {
232         // MSVC defines this as an inline function.
233         int fwide(FILE* stream, int mode) { return mode; }
234     }
235     else
236     {
237         int    fwide(FILE* stream, int mode);
238     }
239 }
240 
241 ///
242 double  wcstod(const scope wchar_t* nptr, wchar_t** endptr);
243 ///
244 float   wcstof(const scope wchar_t* nptr, wchar_t** endptr);
245 ///
246 real    wcstold(const scope wchar_t* nptr, wchar_t** endptr);
247 ///
248 c_long  wcstol(const scope wchar_t* nptr, wchar_t** endptr, int base);
249 ///
250 long    wcstoll(const scope wchar_t* nptr, wchar_t** endptr, int base);
251 ///
252 c_ulong wcstoul(const scope wchar_t* nptr, wchar_t** endptr, int base);
253 ///
254 ulong   wcstoull(const scope wchar_t* nptr, wchar_t** endptr, int base);
255 
256 ///
257 pure wchar_t* wcscpy(return scope wchar_t* s1, scope const wchar_t* s2);
258 ///
259 pure wchar_t* wcsncpy(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
260 ///
261 pure wchar_t* wcscat(return scope wchar_t* s1, scope const wchar_t* s2);
262 ///
263 pure wchar_t* wcsncat(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
264 ///
265 pure int wcscmp(scope const wchar_t* s1, scope const wchar_t* s2);
266 ///
267 int      wcscoll(scope const wchar_t* s1, scope const wchar_t* s2);
268 ///
269 pure int wcsncmp(scope const wchar_t* s1, scope const wchar_t* s2, size_t n);
270 ///
271 size_t   wcsxfrm(scope wchar_t* s1, scope const wchar_t* s2, size_t n);
272 ///
273 pure inout(wchar_t)* wcschr(return scope inout(wchar_t)* s, wchar_t c);
274 ///
275 pure size_t wcscspn(scope const wchar_t* s1, scope const wchar_t* s2);
276 ///
277 pure inout(wchar_t)* wcspbrk(return scope inout(wchar_t)* s1, scope const wchar_t* s2);
278 ///
279 pure inout(wchar_t)* wcsrchr(return scope inout(wchar_t)* s, wchar_t c);
280 ///
281 pure size_t wcsspn(scope const wchar_t* s1, scope const wchar_t* s2);
282 ///
283 pure inout(wchar_t)* wcsstr(return scope inout(wchar_t)* s1, scope const wchar_t* s2);
284 ///
285 wchar_t* wcstok(return scope wchar_t* s1, scope const wchar_t* s2, wchar_t** ptr);
286 ///
287 pure size_t wcslen(scope const wchar_t* s);
288 
289 ///
290 pure inout(wchar_t)* wmemchr(return scope inout wchar_t* s, wchar_t c, size_t n);
291 ///
292 pure int      wmemcmp(scope const wchar_t* s1, scope const wchar_t* s2, size_t n);
293 ///
294 pure wchar_t* wmemcpy(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
295 ///
296 pure wchar_t* wmemmove(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
297 ///
298 pure wchar_t* wmemset(return scope wchar_t* s, wchar_t c, size_t n);
299 
300 ///
301 size_t wcsftime(wchar_t* s, size_t maxsize, const scope wchar_t* format, const scope tm* timeptr);
302 
303 version (Windows)
304 {
305     ///
306     wchar_t* _wasctime(tm*);      // non-standard
307     ///
308     wchar_t* _wctime(time_t*);    // non-standard
309     ///
310     wchar_t* _wstrdate(wchar_t*); // non-standard
311     ///
312     wchar_t* _wstrtime(wchar_t*); // non-standard
313 }
314 
315 // No unsafe pointer manipulation.
316 @trusted
317 {
318     ///
319     wint_t btowc(int c);
320     ///
321     int    wctob(wint_t c);
322 }
323 
324 ///
325 int    mbsinit(const scope mbstate_t* ps);
326 ///
327 size_t mbrlen(const scope char* s, size_t n, mbstate_t* ps);
328 ///
329 size_t mbrtowc(wchar_t* pwc, const scope char* s, size_t n, mbstate_t* ps);
330 ///
331 size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps);
332 ///
333 size_t mbsrtowcs(wchar_t* dst, const scope char** src, size_t len, mbstate_t* ps);
334 ///
335 size_t wcsrtombs(char* dst, const scope wchar_t** src, size_t len, mbstate_t* ps);