The OpenD Programming Language

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 import core.atomic : atomicLoad;
21 public import core.stdc.stddef;  // for wchar_t
22 public import core.stdc.time;    // for tm
23 public import core.stdc.stdint;  // for WCHAR_MIN, WCHAR_MAX
24 
25 extern (C):
26 nothrow:
27 @nogc:
28 
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 version (CRuntime_Glibc)
131 {
132     ///
133     int fwprintf(FILE* stream, const scope wchar_t* format, scope const ...);
134     ///
135     int __isoc99_fwscanf(FILE* stream, const scope wchar_t* format, scope ...);
136     ///
137     alias fwscanf = __isoc99_fwscanf;
138     ///
139     int swprintf(wchar_t* s, size_t n, const scope wchar_t* format, scope const ...);
140     ///
141     int __isoc99_swscanf(const scope wchar_t* s, const scope wchar_t* format, scope ...);
142     ///
143     alias swscanf = __isoc99_swscanf;
144     ///
145     int vfwprintf(FILE* stream, const scope wchar_t* format, va_list arg);
146     ///
147     int __isoc99_vfwscanf(FILE* stream, const scope wchar_t* format, va_list arg);
148     ///
149     alias vfwscanf = __isoc99_vfwscanf;
150     ///
151     int vswprintf(wchar_t* s, size_t n, const scope wchar_t* format, va_list arg);
152     ///
153     int __isoc99_vswscanf(const scope wchar_t* s, const scope wchar_t* format, va_list arg);
154     ///
155     alias vswscanf = __isoc99_vswscanf;
156     ///
157     int vwprintf(const scope wchar_t* format, va_list arg);
158     ///
159     int __isoc99_vwscanf(const scope wchar_t* format, va_list arg);
160     ///
161     alias vwscanf = __isoc99_vwscanf;
162     ///
163     int wprintf(const scope wchar_t* format, scope const ...);
164     ///
165     int __isoc99_wscanf(const scope wchar_t* format, scope ...);
166     ///
167     alias wscanf = __isoc99_wscanf;
168 }
169 else
170 {
171     ///
172     int fwprintf(FILE* stream, const scope wchar_t* format, scope const ...);
173     ///
174     int fwscanf(FILE* stream, const scope wchar_t* format, scope ...);
175     ///
176     int swprintf(wchar_t* s, size_t n, const scope wchar_t* format, scope const ...);
177     ///
178     int swscanf(const scope wchar_t* s, const scope wchar_t* format, scope ...);
179     ///
180     int vfwprintf(FILE* stream, const scope wchar_t* format, va_list arg);
181     ///
182     int vfwscanf(FILE* stream, const scope wchar_t* format, va_list arg);
183     ///
184     int vswprintf(wchar_t* s, size_t n, const scope wchar_t* format, va_list arg);
185     ///
186     int vswscanf(const scope wchar_t* s, const scope wchar_t* format, va_list arg);
187     ///
188     int vwprintf(const scope wchar_t* format, va_list arg);
189     ///
190     int vwscanf(const scope wchar_t* format, va_list arg);
191     ///
192     int wprintf(const scope wchar_t* format, scope const ...);
193     ///
194     int wscanf(const scope wchar_t* format, scope ...);
195 }
196 
197 // No unsafe pointer manipulation.
198 @trusted
199 {
200     ///
201     wint_t fgetwc(FILE* stream);
202     ///
203     wint_t fputwc(wchar_t c, FILE* stream);
204 }
205 
206 ///
207 wchar_t* fgetws(wchar_t* s, int n, FILE* stream);
208 ///
209 int      fputws(const scope wchar_t* s, FILE* stream);
210 
211 // No unsafe pointer manipulation.
212 extern (D) @trusted
213 {
214     ///
215     wint_t getwchar()                     { return fgetwc(atomicLoad(stdin));     }
216     ///
217     wint_t putwchar(wchar_t c)            { return fputwc(c,atomicLoad(stdout));  }
218 }
219 
220 ///
221 alias getwc = fgetwc;
222 ///
223 alias putwc = fputwc;
224 
225 // No unsafe pointer manipulation.
226 @trusted
227 {
228     ///
229     wint_t ungetwc(wint_t c, FILE* stream);
230     ///
231     version (CRuntime_Microsoft)
232     {
233         // MSVC defines this as an inline function.
234         int fwide(FILE* stream, int mode) { return mode; }
235     }
236     else
237     {
238         int    fwide(FILE* stream, int mode);
239     }
240 }
241 
242 ///
243 double  wcstod(const scope wchar_t* nptr, wchar_t** endptr);
244 ///
245 float   wcstof(const scope wchar_t* nptr, wchar_t** endptr);
246 ///
247 real    wcstold(const scope wchar_t* nptr, wchar_t** endptr);
248 ///
249 c_long  wcstol(const scope wchar_t* nptr, wchar_t** endptr, int base);
250 ///
251 long    wcstoll(const scope wchar_t* nptr, wchar_t** endptr, int base);
252 ///
253 c_ulong wcstoul(const scope wchar_t* nptr, wchar_t** endptr, int base);
254 ///
255 ulong   wcstoull(const scope wchar_t* nptr, wchar_t** endptr, int base);
256 
257 ///
258 pure wchar_t* wcscpy(return scope wchar_t* s1, scope const wchar_t* s2);
259 ///
260 pure wchar_t* wcsncpy(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
261 ///
262 pure wchar_t* wcscat(return scope wchar_t* s1, scope const wchar_t* s2);
263 ///
264 pure wchar_t* wcsncat(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
265 ///
266 pure int wcscmp(scope const wchar_t* s1, scope const wchar_t* s2);
267 ///
268 int      wcscoll(scope const wchar_t* s1, scope const wchar_t* s2);
269 ///
270 pure int wcsncmp(scope const wchar_t* s1, scope const wchar_t* s2, size_t n);
271 ///
272 size_t   wcsxfrm(scope wchar_t* s1, scope const wchar_t* s2, size_t n);
273 ///
274 pure inout(wchar_t)* wcschr(return scope inout(wchar_t)* s, wchar_t c);
275 ///
276 pure size_t wcscspn(scope const wchar_t* s1, scope const wchar_t* s2);
277 ///
278 pure inout(wchar_t)* wcspbrk(return scope inout(wchar_t)* s1, scope const wchar_t* s2);
279 ///
280 pure inout(wchar_t)* wcsrchr(return scope inout(wchar_t)* s, wchar_t c);
281 ///
282 pure size_t wcsspn(scope const wchar_t* s1, scope const wchar_t* s2);
283 ///
284 pure inout(wchar_t)* wcsstr(return scope inout(wchar_t)* s1, scope const wchar_t* s2);
285 ///
286 wchar_t* wcstok(return scope wchar_t* s1, scope const wchar_t* s2, wchar_t** ptr);
287 ///
288 pure size_t wcslen(scope const wchar_t* s);
289 
290 ///
291 pure inout(wchar_t)* wmemchr(return scope inout wchar_t* s, wchar_t c, size_t n);
292 ///
293 pure int      wmemcmp(scope const wchar_t* s1, scope const wchar_t* s2, size_t n);
294 ///
295 pure wchar_t* wmemcpy(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
296 ///
297 pure wchar_t* wmemmove(return scope wchar_t* s1, scope const wchar_t* s2, size_t n);
298 ///
299 pure wchar_t* wmemset(return scope wchar_t* s, wchar_t c, size_t n);
300 
301 ///
302 size_t wcsftime(wchar_t* s, size_t maxsize, const scope wchar_t* format, const scope tm* timeptr);
303 
304 version (Windows)
305 {
306     ///
307     wchar_t* _wasctime(tm*);      // non-standard
308     ///
309     wchar_t* _wctime(time_t*);    // non-standard
310     ///
311     wchar_t* _wstrdate(wchar_t*); // non-standard
312     ///
313     wchar_t* _wstrtime(wchar_t*); // non-standard
314 }
315 
316 // No unsafe pointer manipulation.
317 @trusted
318 {
319     ///
320     wint_t btowc(int c);
321     ///
322     int    wctob(wint_t c);
323 }
324 
325 ///
326 int    mbsinit(const scope mbstate_t* ps);
327 ///
328 size_t mbrlen(const scope char* s, size_t n, mbstate_t* ps);
329 ///
330 size_t mbrtowc(wchar_t* pwc, const scope char* s, size_t n, mbstate_t* ps);
331 ///
332 size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps);
333 ///
334 size_t mbsrtowcs(wchar_t* dst, const scope char** src, size_t len, mbstate_t* ps);
335 ///
336 size_t wcsrtombs(char* dst, const scope wchar_t** src, size_t len, mbstate_t* ps);