xref: /haiku/src/system/libroot/posix/glibc/wcsmbs/wchar.h (revision f2b4344867e97c3f4e742a1b4a15e6879644601a)
1 /* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18 
19 /*
20  *      ISO C99 Standard: 7.24
21  *	Extended multibyte and wide character utilities	<wchar.h>
22  */
23 
24 #ifndef _WCHAR_H
25 
26 #ifndef __need_mbstate_t
27 # define _WCHAR_H 1
28 # include <features.h>
29 #endif
30 
31 #ifdef _WCHAR_H
32 /* Get FILE definition.  */
33 # define __need___FILE
34 # ifdef __USE_UNIX98
35 #  define __need_FILE
36 # endif
37 # include <libio/stdio.h>
38 /* Get va_list definition.  */
39 # define __need___va_list
40 # include <stdarg.h>
41 
42 /* Get size_t, wchar_t, wint_t and NULL from <stddef.h>.  */
43 # define __need_size_t
44 # define __need_wchar_t
45 # define __need_NULL
46 #endif
47 #define __need_wint_t
48 #include <stddef.h>
49 
50 #include <bits/wchar.h>
51 
52 /* We try to get wint_t from <stddef.h>, but not all GCC versions define it
53    there.  So define it ourselves if it remains undefined.  */
54 #ifndef _WINT_T
55 /* Integral type unchanged by default argument promotions that can
56    hold any value corresponding to members of the extended character
57    set, as well as at least one value that does not correspond to any
58    member of the extended character set.  */
59 # define _WINT_T
60 typedef unsigned int wint_t;
61 #endif
62 
63 
64 #ifndef __mbstate_t_defined
65 # define __mbstate_t_defined	1
66 /* Conversion state information - for now a mixture between glibc's own idea of
67    mbstate_t and our own.  */
68 typedef struct
69 {
70   void* converter;
71   char charset[64];
72   union
73   {
74     unsigned int count;
75     int __count;
76   };
77   union
78   {
79 	char data[1024 + 8];	// 1024 bytes for data, 8 for alignment space
80 	union
81 	{
82 	  wint_t __wch;
83 	  char __wchb[4];
84 	} __value;		/* Value so far.  */
85   };
86 } __mbstate_t;
87 #endif
88 #undef __need_mbstate_t
89 
90 
91 /* The rest of the file is only used if used if __need_mbstate_t is not
92    defined.  */
93 #ifdef _WCHAR_H
94 
95 /* Public type.  */
96 typedef __mbstate_t mbstate_t;
97 
98 #ifndef WCHAR_MIN
99 /* These constants might also be defined in <inttypes.h>.  */
100 # define WCHAR_MIN __WCHAR_MIN
101 # define WCHAR_MAX __WCHAR_MAX
102 #endif
103 
104 #ifndef WEOF
105 # define WEOF (0xffffffffu)
106 #endif
107 
108 /* For XPG4 compliance we have to define the stuff from <wctype.h> here
109    as well.  */
110 #if defined __USE_XOPEN && !defined __USE_UNIX98
111 # include <wctype.h>
112 #endif
113 
114 /* This incomplete type is defined in <time.h> but needed here because
115    of `wcsftime'.  */
116 struct tm;
117 
118 
119 __BEGIN_DECLS
120 
121 
122 
123 /* Convert initial portion of the wide string NPTR to `double'
124    representation.  */
125 extern double wcstod (__const wchar_t *__restrict __nptr,
126 		      wchar_t **__restrict __endptr) __THROW;
127 
128 #ifdef __USE_ISOC99
129 /* Likewise for `float' and `long double' sizes of floating-point numbers.  */
130 extern float wcstof (__const wchar_t *__restrict __nptr,
131 		     wchar_t **__restrict __endptr) __THROW;
132 extern long double wcstold (__const wchar_t *__restrict __nptr,
133 			    wchar_t **__restrict __endptr) __THROW;
134 #endif /* C99 */
135 
136 
137 /* Convert initial portion of wide string NPTR to `long int'
138    representation.  */
139 extern long int wcstol (__const wchar_t *__restrict __nptr,
140 			wchar_t **__restrict __endptr, int __base) __THROW;
141 
142 /* Convert initial portion of wide string NPTR to `unsigned long int'
143    representation.  */
144 extern unsigned long int wcstoul (__const wchar_t *__restrict __nptr,
145 				  wchar_t **__restrict __endptr, int __base)
146      __THROW;
147 
148 #if defined __GNUC__ && defined __USE_GNU
149 /* Convert initial portion of wide string NPTR to `long int'
150    representation.  */
151 __extension__
152 extern long long int wcstoq (__const wchar_t *__restrict __nptr,
153 			     wchar_t **__restrict __endptr, int __base)
154      __THROW;
155 
156 /* Convert initial portion of wide string NPTR to `unsigned long long int'
157    representation.  */
158 __extension__
159 extern unsigned long long int wcstouq (__const wchar_t *__restrict __nptr,
160 				       wchar_t **__restrict __endptr,
161 				       int __base) __THROW;
162 #endif /* GCC and use GNU.  */
163 
164 #if defined __USE_ISOC99 || (defined __GNUC__ && defined __USE_GNU)
165 /* Convert initial portion of wide string NPTR to `long int'
166    representation.  */
167 __extension__
168 extern long long int wcstoll (__const wchar_t *__restrict __nptr,
169 			      wchar_t **__restrict __endptr, int __base)
170      __THROW;
171 
172 /* Convert initial portion of wide string NPTR to `unsigned long long int'
173    representation.  */
174 __extension__
175 extern unsigned long long int wcstoull (__const wchar_t *__restrict __nptr,
176 					wchar_t **__restrict __endptr,
177 					int __base) __THROW;
178 #endif /* ISO C99 or GCC and GNU.  */
179 
180 
181 /* The internal entry points for `wcstoX' take an extra flag argument
182    saying whether or not to parse locale-dependent number grouping.  */
183 extern double __wcstod_internal (__const wchar_t *__restrict __nptr,
184 				 wchar_t **__restrict __endptr, int __group)
185      __THROW;
186 extern float __wcstof_internal (__const wchar_t *__restrict __nptr,
187 				wchar_t **__restrict __endptr, int __group)
188      __THROW;
189 extern long double __wcstold_internal (__const wchar_t *__restrict __nptr,
190 				       wchar_t **__restrict __endptr,
191 				       int __group) __THROW;
192 
193 #ifndef __wcstol_internal_defined
194 extern long int __wcstol_internal (__const wchar_t *__restrict __nptr,
195 				   wchar_t **__restrict __endptr,
196 				   int __base, int __group) __THROW;
197 # define __wcstol_internal_defined	1
198 #endif
199 #ifndef __wcstoul_internal_defined
200 extern unsigned long int __wcstoul_internal (__const wchar_t *__restrict __npt,
201 					     wchar_t **__restrict __endptr,
202 					     int __base, int __group) __THROW;
203 # define __wcstoul_internal_defined	1
204 #endif
205 #ifndef __wcstoll_internal_defined
206 __extension__
207 extern long long int __wcstoll_internal (__const wchar_t *__restrict __nptr,
208 					 wchar_t **__restrict __endptr,
209 					 int __base, int __group) __THROW;
210 # define __wcstoll_internal_defined	1
211 #endif
212 #ifndef __wcstoull_internal_defined
213 __extension__
214 extern unsigned long long int __wcstoull_internal (__const wchar_t *
215 						   __restrict __nptr,
216 						   wchar_t **
217 						   __restrict __endptr,
218 						   int __base,
219 						   int __group) __THROW;
220 # define __wcstoull_internal_defined	1
221 #endif
222 
223 
224 #if defined __OPTIMIZE__ && __GNUC__ >= 2
225 /* Define inline functions which call the internal entry points.  */
226 
227 extern __inline double wcstod (__const wchar_t *__restrict __nptr,
228 			       wchar_t **__restrict __endptr) __THROW
229 { return __wcstod_internal (__nptr, __endptr, 0); }
230 extern __inline long int wcstol (__const wchar_t *__restrict __nptr,
231                                  wchar_t **__restrict __endptr,
232 				 int __base) __THROW
233 { return __wcstol_internal (__nptr, __endptr, __base, 0); }
234 extern __inline unsigned long int wcstoul (__const wchar_t *__restrict __nptr,
235                                            wchar_t **__restrict __endptr,
236 					   int __base) __THROW
237 { return __wcstoul_internal (__nptr, __endptr, __base, 0); }
238 
239 # ifdef __USE_GNU
240 extern __inline float wcstof (__const wchar_t *__restrict __nptr,
241 			      wchar_t **__restrict __endptr) __THROW
242 { return __wcstof_internal (__nptr, __endptr, 0); }
243 extern __inline long double wcstold (__const wchar_t *__restrict __nptr,
244 				     wchar_t **__restrict __endptr) __THROW
245 { return __wcstold_internal (__nptr, __endptr, 0); }
246 
247 
248 __extension__
249 extern __inline long long int wcstoq (__const wchar_t *__restrict __nptr,
250 				      wchar_t **__restrict __endptr,
251 				      int __base) __THROW
252 { return __wcstoll_internal (__nptr, __endptr, __base, 0); }
253 __extension__
254 extern __inline unsigned long long int wcstouq (__const wchar_t *
255 						__restrict __nptr,
256 						wchar_t **__restrict __endptr,
257 						int __base) __THROW
258 { return __wcstoull_internal (__nptr, __endptr, __base, 0); }
259 # endif /* Use GNU.  */
260 #endif /* Optimizing GCC >=2.  */
261 
262 
263 /* Wide character I/O functions.  */
264 #if defined __USE_ISOC99 || defined __USE_UNIX98
265 
266 /* Select orientation for stream.  */
267 extern int fwide (__FILE *__fp, int __mode) __THROW;
268 
269 
270 /* Write formatted output to STREAM.  */
271 extern int fwprintf (__FILE *__restrict __stream,
272 		     __const wchar_t *__restrict __format, ...)
273      __THROW /* __attribute__ ((__format__ (__wprintf__, 2, 3))) */;
274 /* Write formatted output to stdout.  */
275 extern int wprintf (__const wchar_t *__restrict __format, ...)
276      __THROW /* __attribute__ ((__format__ (__wprintf__, 1, 2))) */;
277 /* Write formatted output of at most N characters to S.  */
278 extern int swprintf (wchar_t *__restrict __s, size_t __n,
279 		     __const wchar_t *__restrict __format, ...)
280      __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 4))) */;
281 
282 /* Write formatted output to S from argument list ARG.  */
283 extern int vfwprintf (__FILE *__restrict __s,
284 		      __const wchar_t *__restrict __format,
285 		      __gnuc_va_list __arg)
286      __THROW /* __attribute__ ((__format__ (__wprintf__, 2, 0))) */;
287 /* Write formatted output to stdout from argument list ARG.  */
288 extern int vwprintf (__const wchar_t *__restrict __format,
289 		     __gnuc_va_list __arg)
290      __THROW /* __attribute__ ((__format__ (__wprintf__, 1, 0))) */;
291 /* Write formatted output of at most N character to S from argument
292    list ARG.  */
293 extern int vswprintf (wchar_t *__restrict __s, size_t __n,
294 		      __const wchar_t *__restrict __format,
295 		      __gnuc_va_list __arg)
296      __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 0))) */;
297 
298 
299 /* Read formatted input from STREAM.  */
300 extern int fwscanf (__FILE *__restrict __stream,
301 		    __const wchar_t *__restrict __format, ...)
302      __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
303 /* Read formatted input from stdin.  */
304 extern int wscanf (__const wchar_t *__restrict __format, ...)
305      __THROW /* __attribute__ ((__format__ (__wscanf__, 1, 2))) */;
306 /* Read formatted input from S.  */
307 extern int swscanf (__const wchar_t *__restrict __s,
308 		    __const wchar_t *__restrict __format, ...)
309      __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
310 #endif /* Use ISO C99 and Unix98. */
311 
312 #ifdef __USE_ISOC99
313 /* Read formatted input from S into argument list ARG.  */
314 extern int vfwscanf (__FILE *__restrict __s,
315 		     __const wchar_t *__restrict __format,
316 		     __gnuc_va_list __arg)
317      __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
318 /* Read formatted input from stdin into argument list ARG.  */
319 extern int vwscanf (__const wchar_t *__restrict __format,
320 		    __gnuc_va_list __arg)
321      __THROW /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */;
322 /* Read formatted input from S into argument list ARG.  */
323 extern int vswscanf (__const wchar_t *__restrict __s,
324 		     __const wchar_t *__restrict __format,
325 		     __gnuc_va_list __arg)
326      __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
327 #endif /* Use ISO C99. */
328 
329 
330 /* Read a character from STREAM.  */
331 extern wint_t fgetwc (__FILE *__stream) __THROW;
332 extern wint_t getwc (__FILE *__stream) __THROW;
333 
334 /* Read a character from stdin.  */
335 extern wint_t getwchar (void) __THROW;
336 
337 
338 /* Write a character to STREAM.  */
339 extern wint_t fputwc (wchar_t __wc, __FILE *__stream) __THROW;
340 extern wint_t putwc (wchar_t __wc, __FILE *__stream) __THROW;
341 
342 /* Write a character to stdout.  */
343 extern wint_t putwchar (wchar_t __wc) __THROW;
344 
345 
346 /* Get a newline-terminated wide character string of finite length
347    from STREAM.  */
348 extern wchar_t *fgetws (wchar_t *__restrict __ws, int __n,
349 			__FILE *__restrict __stream) __THROW;
350 
351 /* Write a string to STREAM.  */
352 extern int fputws (__const wchar_t *__restrict __ws,
353 		   __FILE *__restrict __stream) __THROW;
354 
355 
356 /* Push a character back onto the input buffer of STREAM.  */
357 extern wint_t ungetwc (wint_t __wc, __FILE *__stream) __THROW;
358 
359 
360 #ifdef __USE_GNU
361 /* These are defined to be equivalent to the `char' functions defined
362    in POSIX.1:1996.  */
363 extern wint_t getwc_unlocked (__FILE *__stream) __THROW;
364 extern wint_t getwchar_unlocked (void) __THROW;
365 
366 /* This is the wide character version of a GNU extension.  */
367 extern wint_t fgetwc_unlocked (__FILE *__stream) __THROW;
368 
369 /* Faster version when locking is not necessary.  */
370 extern wint_t fputwc_unlocked (wchar_t __wc, __FILE *__stream) __THROW;
371 
372 /* These are defined to be equivalent to the `char' functions defined
373    in POSIX.1:1996.  */
374 extern wint_t putwc_unlocked (wchar_t __wc, __FILE *__stream) __THROW;
375 extern wint_t putwchar_unlocked (wchar_t __wc) __THROW;
376 
377 
378 /* This function does the same as `fgetws' but does not lock the stream.  */
379 extern wchar_t *fgetws_unlocked (wchar_t *__restrict __ws, int __n,
380 				 __FILE *__restrict __stream) __THROW;
381 
382 /* This function does the same as `fputws' but does not lock the stream.  */
383 extern int fputws_unlocked (__const wchar_t *__restrict __ws,
384 			    __FILE *__restrict __stream) __THROW;
385 #endif
386 
387 
388 __END_DECLS
389 
390 #endif	/* _WCHAR_H defined */
391 
392 #endif /* wchar.h  */
393