Update.
[glibc.git] / wcsmbs / wchar.h
blob48ed81b33ba5ace8469bba7b390fa6ed8d8bbf62
1 /* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * ISO C Standard, Amendment 1, 7.16.4
21 * General wide-string utilities <wchar.h>
24 #ifndef _WCHAR_H
25 #define _WCHAR_H 1
27 #include <features.h>
29 /* Get FILE definition. */
30 #define __need_FILE
31 #include <stdio.h>
33 /* Get size_t, wchar_t, wint_t and NULL from <stddef.h>. */
34 #define __need_size_t
35 #define __need_wchar_t
36 #define __need_wint_t
37 #define __need_NULL
38 #include <stddef.h>
40 /* We try to get wint_t from <stddef.h>, but not all GCC versions define it
41 there. So define it ourselves if it remains undefined. */
42 #ifndef _WINT_T
43 /* Integral type unchanged by default argument promotions that can
44 hold any value corresponding to members of the extended character
45 set, as well as at least one value that does not correspond to any
46 member of the extended character set. */
47 # define _WINT_T
48 typedef unsigned int wint_t;
49 #endif
52 /* Conversion state information. */
53 typedef struct
55 int count; /* Number of bytes needed for the current character. */
56 wint_t value; /* Value so far. */
57 } mbstate_t;
59 #ifndef WCHAR_MIN
60 /* These constants might also be defined in <inttypes.h>. */
61 # define WCHAR_MIN ((wchar_t) 0)
62 # define WCHAR_MAX (~WCHAR_MIN)
63 #endif
65 #ifndef WEOF
66 # define WEOF (0xffffffffu)
67 #endif
69 /* This incomplete type is defined in <time.h> but needed here because
70 of `wcsftime'. */
71 struct tm;
74 __BEGIN_DECLS
76 /* Copy SRC to DEST. */
77 extern wchar_t *wcscpy __P ((wchar_t *__restrict __dest,
78 __const wchar_t *__restrict __src));
79 /* Copy no more than N wide-characters of SRC to DEST. */
80 extern wchar_t *wcsncpy __P ((wchar_t *__restrict __dest,
81 __const wchar_t *__restrict __src, size_t __n));
83 /* Append SRC onto DEST. */
84 extern wchar_t *wcscat __P ((wchar_t *__restrict __dest,
85 __const wchar_t *__restrict __src));
86 /* Append no more than N wide-characters of SRC onto DEST. */
87 extern wchar_t *wcsncat __P ((wchar_t *__restrict __dest,
88 __const wchar_t *__restrict __src, size_t __n));
90 /* Compare S1 and S2. */
91 extern int wcscmp __P ((__const wchar_t *__s1, __const wchar_t *__s2));
92 /* Compare N wide-characters of S1 and S2. */
93 extern int wcsncmp __P ((__const wchar_t *__s1, __const wchar_t *__s2,
94 size_t __n));
96 #ifdef __USE_GNU
97 /* Compare S1 and S2, ignoring case. */
98 extern int __wcscasecmp __P ((__const wchar_t *__s1, __const wchar_t *__s2));
99 extern int wcscasecmp __P ((__const wchar_t *__s1, __const wchar_t *__s2));
101 /* Compare no more than N chars of S1 and S2, ignoring case. */
102 extern int __wcsncasecmp __P ((__const wchar_t *__s1, __const wchar_t *__s2,
103 size_t __n));
104 extern int wcsncasecmp __P ((__const wchar_t *__s1, __const wchar_t *__s2,
105 size_t __n));
107 /* Similar to the two functions above but take the information from
108 the provided locale and not the global locale. */
109 # include <xlocale.h>
111 extern int __wcscasecmp_l __P ((__const wchar_t *__s1, __const wchar_t *__s2,
112 __locale_t __loc));
114 extern int __wcsncasecmp_l __P ((__const wchar_t *__s1, __const wchar_t *__s2,
115 size_t __n, __locale_t __loc));
116 #endif
118 /* Compare S1 and S2, both interpreted as appropriate to the
119 LC_COLLATE category of the current locale. */
120 extern int wcscoll __P ((__const wchar_t *__s1, __const wchar_t *__s2));
121 /* Transform S2 into array pointed to by S1 such that if wcscmp is
122 applied to two transformed strings the result is the as applying
123 `wcscoll' to the original strings. */
124 extern size_t wcsxfrm __P ((wchar_t *__restrict __s1,
125 __const wchar_t *__restrict __s2, size_t __n));
127 #ifdef __USE_GNU
128 /* Similar to the two functions above but take the information from
129 the provided locale and not the global locale. */
131 /* Compare S1 and S2, both interpreted as appropriate to the
132 LC_COLLATE category of the given locale. */
133 extern int __wcscoll_l __P ((__const wchar_t *__s1, __const wchar_t *__s2,
134 __locale_t __loc));
135 /* Transform S2 into array pointed to by S1 such that if wcscmp is
136 applied to two transformed strings the result is the as applying
137 `wcscoll' to the original strings. */
138 extern size_t __wcsxfrm_l __P ((wchar_t *__s1, __const wchar_t *__s2,
139 size_t __n, __locale_t __loc));
141 /* Duplicate S, returning an identical malloc'd string. */
142 extern wchar_t *wcsdup __P ((__const wchar_t *__s));
143 #endif
145 /* Find the first occurrence of WC in WCS. */
146 extern wchar_t *wcschr __P ((__const wchar_t *__wcs, wchar_t __wc));
147 /* Find the last occurrence of WC in WCS. */
148 extern wchar_t *wcsrchr __P ((__const wchar_t *__wcs, wchar_t __wc));
150 /* Return the length of the initial segmet of WCS which
151 consists entirely of wide characters not in REJECT. */
152 extern size_t wcscspn __P ((__const wchar_t *__wcs,
153 __const wchar_t *__reject));
154 /* Return the length of the initial segmet of WCS which
155 consists entirely of wide characters in ACCEPT. */
156 extern size_t wcsspn __P ((__const wchar_t *__wcs, __const wchar_t *__accept));
157 /* Find the first occurrence in WCS of any character in ACCEPT. */
158 extern wchar_t *wcspbrk __P ((__const wchar_t *__wcs,
159 __const wchar_t *__accept));
160 /* Find the first occurrence of NEEDLE in HAYSTACK. */
161 extern wchar_t *wcsstr __P ((__const wchar_t *__haystack,
162 __const wchar_t *__needle));
163 /* Divide WCS into tokens separated by characters in DELIM. */
164 extern wchar_t *wcstok __P ((wchar_t *__restrict __s,
165 __const wchar_t *__restrict __delim,
166 wchar_t **__restrict __ptr));
168 /* Return the number of wide characters in S. */
169 extern size_t __wcslen __P ((__const wchar_t *__s));
170 extern size_t wcslen __P ((__const wchar_t *__s));
172 #ifdef __USE_GNU
173 /* Return the number of wide characters in S, but at most MAXLEN. */
174 extern size_t __wcsnlen __P ((__const wchar_t *__s, size_t __maxlen));
175 extern size_t wcsnlen __P ((__const wchar_t *__s, size_t __maxlen));
176 #endif
179 /* Search N wide characters of S for C. */
180 extern wchar_t *wmemchr __P ((__const wchar_t *__s, wchar_t __c, size_t __n));
182 /* Compare N wide characters of S1 and S2. */
183 extern int wmemcmp __P ((__const wchar_t *__restrict __s1,
184 __const wchar_t *__restrict __s2, size_t __n));
186 /* Copy N wide characters of SRC to DEST. */
187 extern wchar_t *wmemcpy __P ((wchar_t *__restrict __s1,
188 __const wchar_t *__restrict __s2, size_t __n));
190 /* Copy N wide characters of SRC to DEST, guaranteeing
191 correct behavior for overlapping strings. */
192 extern wchar_t *wmemmove __P ((wchar_t *__s1, __const wchar_t *__s2,
193 size_t __n));
195 /* Set N wide characters of S to C. */
196 extern wchar_t *wmemset __P ((wchar_t *__s, wchar_t __c, size_t __n));
199 /* Determine whether C constitutes a valid (one-byte) multibyte
200 character. */
201 extern wint_t __btowc __P ((int __c));
202 extern wint_t btowc __P ((int __c));
204 /* Determine whether C corresponds to a member of the extended
205 character set whose multibyte representation is a single byte. */
206 extern int wctob __P ((wint_t __c));
208 /* Determine whether PS points to an object representing the initial
209 state. */
210 extern int __mbsinit __P ((__const mbstate_t *__ps));
211 extern int mbsinit __P ((__const mbstate_t *__ps));
213 /* Write wide character representation of multibyte character pointed
214 to by S to PWC. */
215 extern size_t __mbrtowc __P ((wchar_t *__restrict __pwc,
216 __const char *__restrict __s, size_t __n,
217 mbstate_t *__restrict __p));
218 extern size_t mbrtowc __P ((wchar_t *__restrict __pwc,
219 __const char *__restrict __s, size_t __n,
220 mbstate_t *__p));
222 /* Write multibyte representation of wide character WC to S. */
223 extern size_t __wcrtomb __P ((char *__restrict __s, wchar_t __wc,
224 mbstate_t *__restrict __ps));
225 extern size_t wcrtomb __P ((char *__restrict __s, wchar_t __wc,
226 mbstate_t *__restrict __ps));
228 /* Return number of bytes in multibyte character pointed to by S. */
229 extern size_t __mbrlen __P ((__const char *__restrict __s, size_t __n,
230 mbstate_t *__restrict __ps));
231 extern size_t mbrlen __P ((__const char *__restrict __s, size_t __n,
232 mbstate_t *__restrict __ps));
234 #if defined __OPTIMIZE__ \
235 && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
236 /* Define inline function as optimization. */
237 extern __inline size_t mbrlen (__const char *__restrict __s, size_t __n,
238 mbstate_t *__restrict __ps)
239 { return (__ps != NULL
240 ? __mbrtowc (NULL, __s, __n, __ps) : __mbrlen (__s, __n, NULL)); }
241 #endif
243 /* Write wide character representation of multibyte character string
244 SRC to DST. */
245 extern size_t __mbsrtowcs __P ((wchar_t *__restrict __dst,
246 __const char **__restrict __src,
247 size_t __len, mbstate_t *__restrict __ps));
248 extern size_t mbsrtowcs __P ((wchar_t *__restrict __dst,
249 __const char **__restrict __src,
250 size_t __len, mbstate_t *__restrict __ps));
252 /* Write multibyte character representation of wide character string
253 SRC to DST. */
254 extern size_t __wcsrtombs __P ((char *__restrict __dst,
255 __const wchar_t **__restrict __src,
256 size_t __len, mbstate_t *__restrict __ps));
257 extern size_t wcsrtombs __P ((char *__restrict __dst,
258 __const wchar_t **__restrict __src,
259 size_t __len, mbstate_t *__restrict __ps));
262 #ifdef __USE_GNU
263 /* Write wide character representation of at most NMC bytes of the
264 multibyte character string SRC to DST. */
265 extern size_t __mbsnrtowcs __P ((wchar_t *__restrict __dst,
266 __const char **__restrict __src, size_t __nmc,
267 size_t __len, mbstate_t *__restrict __ps));
268 extern size_t mbsnrtowcs __P ((wchar_t *__restrict __dst,
269 __const char **__restrict __src, size_t __nmc,
270 size_t __len, mbstate_t *__restrict __ps));
272 /* Write multibyte character representation of at most NWC characters
273 from the wide character string SRC to DST. */
274 extern size_t __wcsnrtombs __P ((char *__restrict __dst,
275 __const wchar_t **__restrict __src,
276 size_t __nwc, size_t __len,
277 mbstate_t *__restrict __ps));
278 extern size_t wcsnrtombs __P ((char *__restrict __dst,
279 __const wchar_t **__restrict __src,
280 size_t __nwc, size_t __len,
281 mbstate_t *__restrict __ps));
282 #endif /* use GNU */
285 /* The following functions are extensions found in X/Open CAE. */
286 #ifdef __USE_XOPEN
287 /* Determine number of column positions required for C. */
288 extern int wcwidth __P ((wint_t __c));
290 /* Determine number of column positions required for first N wide
291 characters (or fewer if S ends before this) in S. */
292 extern int wcswidth __P ((__const wchar_t *__s, size_t __n));
293 #endif /* Use X/Open. */
296 /* Convert initial portion of the wide string NPTR to `double'
297 representation. */
298 extern double wcstod __P ((__const wchar_t *__restrict __nptr,
299 wchar_t **__restrict __endptr));
301 #ifdef __USE_GNU
302 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
303 extern float wcstof __P ((__const wchar_t *__restrict __nptr,
304 wchar_t **__restrict __endptr));
305 extern __long_double_t wcstold __P ((__const wchar_t *__restrict __nptr,
306 wchar_t **__restrict __endptr));
307 #endif /* GNU */
310 /* Convert initial portion of wide string NPTR to `long int'
311 representation. */
312 extern long int wcstol __P ((__const wchar_t *__restrict __nptr,
313 wchar_t **__restrict __endptr, int __base));
315 /* Convert initial portion of wide string NPTR to `unsigned long int'
316 representation. */
317 extern unsigned long int wcstoul __P ((__const wchar_t *__restrict __nptr,
318 wchar_t **__restrict __endptr,
319 int __base));
321 #if defined __GNUC__ && defined __USE_GNU
322 /* Convert initial portion of wide string NPTR to `long int'
323 representation. */
324 extern long long int wcstoq __P ((__const wchar_t *__restrict __nptr,
325 wchar_t **__restrict __endptr, int __base));
327 /* Convert initial portion of wide string NPTR to `unsigned long long int'
328 representation. */
329 extern unsigned long long int wcstouq __P ((__const wchar_t *__restrict __nptr,
330 wchar_t **__restrict __endptr,
331 int __base));
332 #endif /* GCC and use GNU. */
334 #if defined __USE_ISOC9X || (defined __GNUC__ && defined __USE_GNU)
335 /* Convert initial portion of wide string NPTR to `long int'
336 representation. */
337 extern long long int wcstoll __P ((__const wchar_t *__restrict __nptr,
338 wchar_t **__restrict __endptr, int __base));
340 /* Convert initial portion of wide string NPTR to `unsigned long long int'
341 representation. */
342 extern unsigned long long int wcstoull __P ((__const wchar_t *
343 __restrict __nptr,
344 wchar_t **__restrict __endptr,
345 int __base));
346 #endif /* ISO C 9X or GCC and GNU. */
348 #ifdef __USE_GNU
349 /* The concept of one static locale per category is not very well
350 thought out. Many applications will need to process its data using
351 information from several different locales. Another application is
352 the implementation of the internationalization handling in the
353 upcoming ISO C++ standard library. To support this another set of
354 the functions using locale data exist which have an additional
355 argument.
357 Attention: all these functions are *not* standardized in any form.
358 This is a proof-of-concept implementation. */
360 /* Structure for reentrant locale using functions. This is an
361 (almost) opaque type for the user level programs. */
362 # include <xlocale.h>
364 /* Special versions of the functions above which take the locale to
365 use as an additional parameter. */
366 extern long int __wcstol_l __P ((__const wchar_t *__restrict __nptr,
367 wchar_t **__restrict __endptr, int __base,
368 __locale_t __loc));
370 extern unsigned long int __wcstoul_l __P ((__const wchar_t *__restrict __nptr,
371 wchar_t **__restrict __endptr,
372 int __base, __locale_t __loc));
374 extern long long int __wcstoll_l __P ((__const wchar_t *__restrict __nptr,
375 wchar_t **__restrict __endptr,
376 int __base, __locale_t __loc));
378 extern unsigned long long int __wcstoull_l __P ((__const wchar_t *__restrict
379 __nptr,
380 wchar_t **__restrict __endptr,
381 int __base,
382 __locale_t __loc));
384 extern double __wcstod_l __P ((__const wchar_t *__restrict __nptr,
385 wchar_t **__restrict __endptr,
386 __locale_t __loc));
388 extern float __wcstof_l __P ((__const wchar_t *__restrict __nptr,
389 wchar_t **__restrict __endptr,
390 __locale_t __loc));
392 extern __long_double_t __wcstold_l __P ((__const wchar_t *__restrict __nptr,
393 wchar_t **__restrict __endptr,
394 __locale_t __loc));
395 #endif /* GNU */
398 /* The internal entry points for `wcstoX' take an extra flag argument
399 saying whether or not to parse locale-dependent number grouping. */
400 extern double __wcstod_internal __P ((__const wchar_t *__restrict __nptr,
401 wchar_t **__restrict __endptr,
402 int __group));
403 extern float __wcstof_internal __P ((__const wchar_t *__restrict __nptr,
404 wchar_t **__restrict __endptr,
405 int __group));
406 extern __long_double_t __wcstold_internal __P ((__const wchar_t *
407 __restrict __nptr,
408 wchar_t **__restrict __endptr,
409 int __group));
411 #ifndef __wcstol_internal_defined
412 extern long int __wcstol_internal __P ((__const wchar_t *__restrict __nptr,
413 wchar_t **__restrict __endptr,
414 int __base, int __group));
415 # define __wcstol_internal_defined 1
416 #endif
417 #ifndef __wcstoul_internal_defined
418 extern unsigned long int __wcstoul_internal __P ((__const wchar_t *
419 __restrict __nptr,
420 wchar_t **
421 __restrict __endptr,
422 int __base, int __group));
423 # define __wcstoul_internal_defined 1
424 #endif
425 #ifndef __wcstoll_internal_defined
426 extern long long int __wcstoll_internal __P ((__const wchar_t *
427 __restrict __nptr,
428 wchar_t **__restrict __endptr,
429 int __base, int __group));
430 # define __wcstoll_internal_defined 1
431 #endif
432 #ifndef __wcstoull_internal_defined
433 extern unsigned long long int __wcstoull_internal __P ((__const wchar_t *
434 __restrict __nptr,
435 wchar_t **
436 __restrict __endptr,
437 int __base,
438 int __group));
439 # define __wcstoull_internal_defined 1
440 #endif
443 #if defined __OPTIMIZE__ && __GNUC__ >= 2
444 /* Define inline functions which call the internal entry points. */
446 extern __inline double wcstod (__const wchar_t *__restrict __nptr,
447 wchar_t **__restrict __endptr)
448 { return __wcstod_internal (__nptr, __endptr, 0); }
449 extern __inline long int wcstol (__const wchar_t *__restrict __nptr,
450 wchar_t **__restrict __endptr, int __base)
451 { return __wcstol_internal (__nptr, __endptr, __base, 0); }
452 extern __inline unsigned long int wcstoul (__const wchar_t *__restrict __nptr,
453 wchar_t **__restrict __endptr,
454 int __base)
455 { return __wcstoul_internal (__nptr, __endptr, __base, 0); }
457 # ifdef __USE_GNU
458 extern __inline float wcstof (__const wchar_t *__restrict __nptr,
459 wchar_t **__restrict __endptr)
460 { return __wcstof_internal (__nptr, __endptr, 0); }
461 extern __inline __long_double_t wcstold (__const wchar_t *__restrict __nptr,
462 wchar_t **__restrict __endptr)
463 { return __wcstold_internal (__nptr, __endptr, 0); }
466 extern __inline long long int wcstoq (__const wchar_t *__restrict __nptr,
467 wchar_t **__restrict __endptr,
468 int __base)
469 { return __wcstoll_internal (__nptr, __endptr, __base, 0); }
470 extern __inline unsigned long long int wcstouq (__const wchar_t *
471 __restrict __nptr,
472 wchar_t **__restrict __endptr,
473 int __base)
474 { return __wcstoull_internal (__nptr, __endptr, __base, 0); }
475 # endif /* Use GNU. */
476 #endif /* Optimizing GCC >=2. */
479 #ifdef __USE_GNU
480 /* Copy SRC to DEST, returning the address of the terminating L'\0' in
481 DEST. */
482 extern wchar_t *__wcpcpy __P ((wchar_t *__dest, __const wchar_t *__src));
483 extern wchar_t *wcpcpy __P ((wchar_t *__dest, __const wchar_t *__src));
485 /* Copy no more than N characters of SRC to DEST, returning the address of
486 the last character written into DEST. */
487 extern wchar_t *__wcpncpy __P ((wchar_t *__dest, __const wchar_t *__src,
488 size_t __n));
489 extern wchar_t *wcpncpy __P ((wchar_t *__dest, __const wchar_t *__src,
490 size_t __n));
491 #endif /* use GNU */
494 /* The X/Open standard demands that most of the functions defined in
495 the <wctype.h> header must also appear here. This is probably
496 because some X/Open members wrote their implementation before the
497 ISO C standard was published and introduced the better solution.
498 We have to provide these definitions for compliance reasons but we
499 do this nonsense only if really necessary. */
500 #if defined __USE_UNIX98 && !defined __USE_GNU
501 # define __need_iswxxx
502 # include <wctype.h>
503 #endif
505 __END_DECLS
507 #endif /* wchar.h */