]> git.ipfire.org Git - thirdparty/glibc.git/blame - wcsmbs/wchar.h
Update.
[thirdparty/glibc.git] / wcsmbs / wchar.h
CommitLineData
4bca4c17 1/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
b5791037 2 This file is part of the GNU C Library.
30de3b18 3
b5791037
UD
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.
30de3b18 8
b5791037
UD
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.
30de3b18 13
b5791037
UD
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. */
30de3b18
RM
18
19/*
b5791037
UD
20 * ISO C Standard, Amendment 1, 7.16.4
21 * General wide-string utilities <wchar.h>
30de3b18
RM
22 */
23
24#ifndef _WCHAR_H
30de3b18 25#define _WCHAR_H 1
5107cf1d 26
30de3b18
RM
27#include <features.h>
28
9756dfe1
UD
29/* Get FILE definition. */
30#define __need_FILE
31#include <stdio.h>
30de3b18 32
59dd8641 33/* Get size_t, wchar_t, wint_t and NULL from <stddef.h>. */
30de3b18
RM
34#define __need_size_t
35#define __need_wchar_t
59dd8641 36#define __need_wint_t
30de3b18 37#define __need_NULL
30de3b18
RM
38#include <stddef.h>
39
71a40c74
RM
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. */
dfd2257a 47# define _WINT_T
71a40c74
RM
48typedef unsigned int wint_t;
49#endif
50
51
30de3b18 52/* Conversion state information. */
07a4742f
RM
53typedef struct
54{
55 int count; /* Number of bytes needed for the current character. */
56 wint_t value; /* Value so far. */
57} mbstate_t;
30de3b18 58
cc3fa755
UD
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
30de3b18
RM
64
65#ifndef WEOF
66# define WEOF (0xffffffffu)
67#endif
68
e918a7fe
UD
69/* For XPG4 compliance we have to define the stuff from <wctype.h> here
70 as well. */
71#if defined __USE_XOPEN && !defined __USE_UNIX98
72# include <wctype.h>
73#endif
74
9756dfe1
UD
75/* This incomplete type is defined in <time.h> but needed here because
76 of `wcsftime'. */
77struct tm;
78
79
80__BEGIN_DECLS
30de3b18
RM
81
82/* Copy SRC to DEST. */
2f6d1f1b
UD
83extern wchar_t *wcscpy __P ((wchar_t *__restrict __dest,
84 __const wchar_t *__restrict __src));
30de3b18 85/* Copy no more than N wide-characters of SRC to DEST. */
2f6d1f1b
UD
86extern wchar_t *wcsncpy __P ((wchar_t *__restrict __dest,
87 __const wchar_t *__restrict __src, size_t __n));
30de3b18
RM
88
89/* Append SRC onto DEST. */
2f6d1f1b
UD
90extern wchar_t *wcscat __P ((wchar_t *__restrict __dest,
91 __const wchar_t *__restrict __src));
30de3b18 92/* Append no more than N wide-characters of SRC onto DEST. */
2f6d1f1b
UD
93extern wchar_t *wcsncat __P ((wchar_t *__restrict __dest,
94 __const wchar_t *__restrict __src, size_t __n));
30de3b18
RM
95
96/* Compare S1 and S2. */
97extern int wcscmp __P ((__const wchar_t *__s1, __const wchar_t *__s2));
98/* Compare N wide-characters of S1 and S2. */
99extern int wcsncmp __P ((__const wchar_t *__s1, __const wchar_t *__s2,
100 size_t __n));
101
2f6d1f1b
UD
102#ifdef __USE_GNU
103/* Compare S1 and S2, ignoring case. */
2f6d1f1b
UD
104extern int wcscasecmp __P ((__const wchar_t *__s1, __const wchar_t *__s2));
105
106/* Compare no more than N chars of S1 and S2, ignoring case. */
2f6d1f1b
UD
107extern int wcsncasecmp __P ((__const wchar_t *__s1, __const wchar_t *__s2,
108 size_t __n));
0501d603
UD
109
110/* Similar to the two functions above but take the information from
111 the provided locale and not the global locale. */
112# include <xlocale.h>
113
114extern int __wcscasecmp_l __P ((__const wchar_t *__s1, __const wchar_t *__s2,
115 __locale_t __loc));
116
117extern int __wcsncasecmp_l __P ((__const wchar_t *__s1, __const wchar_t *__s2,
118 size_t __n, __locale_t __loc));
2f6d1f1b
UD
119#endif
120
75cd5204
RM
121/* Compare S1 and S2, both interpreted as appropriate to the
122 LC_COLLATE category of the current locale. */
123extern int wcscoll __P ((__const wchar_t *__s1, __const wchar_t *__s2));
124/* Transform S2 into array pointed to by S1 such that if wcscmp is
125 applied to two transformed strings the result is the as applying
126 `wcscoll' to the original strings. */
2f6d1f1b
UD
127extern size_t wcsxfrm __P ((wchar_t *__restrict __s1,
128 __const wchar_t *__restrict __s2, size_t __n));
75cd5204 129
c84142e8
UD
130#ifdef __USE_GNU
131/* Similar to the two functions above but take the information from
132 the provided locale and not the global locale. */
c84142e8
UD
133
134/* Compare S1 and S2, both interpreted as appropriate to the
135 LC_COLLATE category of the given locale. */
136extern int __wcscoll_l __P ((__const wchar_t *__s1, __const wchar_t *__s2,
2f6d1f1b 137 __locale_t __loc));
c84142e8
UD
138/* Transform S2 into array pointed to by S1 such that if wcscmp is
139 applied to two transformed strings the result is the as applying
140 `wcscoll' to the original strings. */
141extern size_t __wcsxfrm_l __P ((wchar_t *__s1, __const wchar_t *__s2,
2f6d1f1b 142 size_t __n, __locale_t __loc));
c84142e8 143
30de3b18
RM
144/* Duplicate S, returning an identical malloc'd string. */
145extern wchar_t *wcsdup __P ((__const wchar_t *__s));
1618c590 146#endif
30de3b18 147
6d52618b 148/* Find the first occurrence of WC in WCS. */
30de3b18 149extern wchar_t *wcschr __P ((__const wchar_t *__wcs, wchar_t __wc));
6d52618b 150/* Find the last occurrence of WC in WCS. */
30de3b18
RM
151extern wchar_t *wcsrchr __P ((__const wchar_t *__wcs, wchar_t __wc));
152
153/* Return the length of the initial segmet of WCS which
1618c590 154 consists entirely of wide characters not in REJECT. */
30de3b18
RM
155extern size_t wcscspn __P ((__const wchar_t *__wcs,
156 __const wchar_t *__reject));
157/* Return the length of the initial segmet of WCS which
1618c590 158 consists entirely of wide characters in ACCEPT. */
30de3b18 159extern size_t wcsspn __P ((__const wchar_t *__wcs, __const wchar_t *__accept));
6d52618b 160/* Find the first occurrence in WCS of any character in ACCEPT. */
30de3b18
RM
161extern wchar_t *wcspbrk __P ((__const wchar_t *__wcs,
162 __const wchar_t *__accept));
6d52618b 163/* Find the first occurrence of NEEDLE in HAYSTACK. */
30de3b18
RM
164extern wchar_t *wcsstr __P ((__const wchar_t *__haystack,
165 __const wchar_t *__needle));
e918a7fe
UD
166
167#if defined __USE_XOPEN && !defined __USE_UNIX98
168/* Another name for `wcsstr' from XPG4. */
169extern wchar_t *wcswcs __P ((__const wchar_t *__haystack,
170 __const wchar_t *__needle));
171#endif
172
30de3b18 173/* Divide WCS into tokens separated by characters in DELIM. */
2f6d1f1b
UD
174extern wchar_t *wcstok __P ((wchar_t *__restrict __s,
175 __const wchar_t *__restrict __delim,
176 wchar_t **__restrict __ptr));
30de3b18 177
1618c590 178/* Return the number of wide characters in S. */
4bca4c17 179extern size_t __wcslen __P ((__const wchar_t *__s));
30de3b18
RM
180extern size_t wcslen __P ((__const wchar_t *__s));
181
4bca4c17
UD
182#ifdef __USE_GNU
183/* Return the number of wide characters in S, but at most MAXLEN. */
4bca4c17
UD
184extern size_t wcsnlen __P ((__const wchar_t *__s, size_t __maxlen));
185#endif
186
30de3b18 187
1618c590 188/* Search N wide characters of S for C. */
30de3b18
RM
189extern wchar_t *wmemchr __P ((__const wchar_t *__s, wchar_t __c, size_t __n));
190
1618c590 191/* Compare N wide characters of S1 and S2. */
2f6d1f1b
UD
192extern int wmemcmp __P ((__const wchar_t *__restrict __s1,
193 __const wchar_t *__restrict __s2, size_t __n));
30de3b18 194
1618c590 195/* Copy N wide characters of SRC to DEST. */
2f6d1f1b
UD
196extern wchar_t *wmemcpy __P ((wchar_t *__restrict __s1,
197 __const wchar_t *__restrict __s2, size_t __n));
30de3b18 198
1618c590 199/* Copy N wide characters of SRC to DEST, guaranteeing
30de3b18
RM
200 correct behavior for overlapping strings. */
201extern wchar_t *wmemmove __P ((wchar_t *__s1, __const wchar_t *__s2,
036cc82f 202 size_t __n));
30de3b18 203
1618c590 204/* Set N wide characters of S to C. */
30de3b18
RM
205extern wchar_t *wmemset __P ((wchar_t *__s, wchar_t __c, size_t __n));
206
207
208/* Determine whether C constitutes a valid (one-byte) multibyte
209 character. */
210extern wint_t btowc __P ((int __c));
211
212/* Determine whether C corresponds to a member of the extended
213 character set whose multibyte representation is a single byte. */
214extern int wctob __P ((wint_t __c));
215
216/* Determine whether PS points to an object representing the initial
217 state. */
218extern int mbsinit __P ((__const mbstate_t *__ps));
219
30de3b18
RM
220/* Write wide character representation of multibyte character pointed
221 to by S to PWC. */
2f6d1f1b
UD
222extern size_t mbrtowc __P ((wchar_t *__restrict __pwc,
223 __const char *__restrict __s, size_t __n,
30de3b18
RM
224 mbstate_t *__p));
225
226/* Write multibyte representation of wide character WC to S. */
2f6d1f1b
UD
227extern size_t wcrtomb __P ((char *__restrict __s, wchar_t __wc,
228 mbstate_t *__restrict __ps));
30de3b18 229
07a4742f 230/* Return number of bytes in multibyte character pointed to by S. */
2f6d1f1b
UD
231extern size_t __mbrlen __P ((__const char *__restrict __s, size_t __n,
232 mbstate_t *__restrict __ps));
233extern size_t mbrlen __P ((__const char *__restrict __s, size_t __n,
234 mbstate_t *__restrict __ps));
07a4742f 235
bdbf022d 236#if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ \
0c6cee5d 237 && defined __USE_EXTERN_INLINES
07a4742f 238/* Define inline function as optimization. */
99e46354
UD
239extern __inline size_t mbrlen (__const char *__restrict __s, size_t __n,
240 mbstate_t *__restrict __ps) __THROW
2f6d1f1b 241{ return (__ps != NULL
bdbf022d 242 ? mbrtowc (NULL, __s, __n, __ps) : __mbrlen (__s, __n, NULL)); }
07a4742f
RM
243#endif
244
036cc82f
RM
245/* Write wide character representation of multibyte character string
246 SRC to DST. */
2f6d1f1b
UD
247extern size_t mbsrtowcs __P ((wchar_t *__restrict __dst,
248 __const char **__restrict __src,
249 size_t __len, mbstate_t *__restrict __ps));
30de3b18
RM
250
251/* Write multibyte character representation of wide character string
252 SRC to DST. */
2f6d1f1b
UD
253extern size_t wcsrtombs __P ((char *__restrict __dst,
254 __const wchar_t **__restrict __src,
255 size_t __len, mbstate_t *__restrict __ps));
30de3b18 256
75cd5204
RM
257
258#ifdef __USE_GNU
036cc82f
RM
259/* Write wide character representation of at most NMC bytes of the
260 multibyte character string SRC to DST. */
2f6d1f1b
UD
261extern size_t mbsnrtowcs __P ((wchar_t *__restrict __dst,
262 __const char **__restrict __src, size_t __nmc,
263 size_t __len, mbstate_t *__restrict __ps));
036cc82f
RM
264
265/* Write multibyte character representation of at most NWC characters
266 from the wide character string SRC to DST. */
2f6d1f1b
UD
267extern size_t wcsnrtombs __P ((char *__restrict __dst,
268 __const wchar_t **__restrict __src,
269 size_t __nwc, size_t __len,
270 mbstate_t *__restrict __ps));
9756dfe1 271#endif /* use GNU */
e34b0f29 272
036cc82f 273
75cd5204 274/* The following functions are extensions found in X/Open CAE. */
9756dfe1 275#ifdef __USE_XOPEN
75cd5204
RM
276/* Determine number of column positions required for C. */
277extern int wcwidth __P ((wint_t __c));
278
279/* Determine number of column positions required for first N wide
280 characters (or fewer if S ends before this) in S. */
281extern int wcswidth __P ((__const wchar_t *__s, size_t __n));
9756dfe1 282#endif /* Use X/Open. */
75cd5204
RM
283
284
285/* Convert initial portion of the wide string NPTR to `double'
286 representation. */
2f6d1f1b
UD
287extern double wcstod __P ((__const wchar_t *__restrict __nptr,
288 wchar_t **__restrict __endptr));
75cd5204 289
fa0bc87c 290#ifdef __USE_GNU
75cd5204 291/* Likewise for `float' and `long double' sizes of floating-point numbers. */
2f6d1f1b
UD
292extern float wcstof __P ((__const wchar_t *__restrict __nptr,
293 wchar_t **__restrict __endptr));
294extern __long_double_t wcstold __P ((__const wchar_t *__restrict __nptr,
295 wchar_t **__restrict __endptr));
75cd5204
RM
296#endif /* GNU */
297
298
299/* Convert initial portion of wide string NPTR to `long int'
300 representation. */
2f6d1f1b
UD
301extern long int wcstol __P ((__const wchar_t *__restrict __nptr,
302 wchar_t **__restrict __endptr, int __base));
75cd5204
RM
303
304/* Convert initial portion of wide string NPTR to `unsigned long int'
305 representation. */
2f6d1f1b
UD
306extern unsigned long int wcstoul __P ((__const wchar_t *__restrict __nptr,
307 wchar_t **__restrict __endptr,
308 int __base));
75cd5204 309
2f6d1f1b 310#if defined __GNUC__ && defined __USE_GNU
75cd5204
RM
311/* Convert initial portion of wide string NPTR to `long int'
312 representation. */
7782d0bf 313__extension__
2f6d1f1b
UD
314extern long long int wcstoq __P ((__const wchar_t *__restrict __nptr,
315 wchar_t **__restrict __endptr, int __base));
75cd5204
RM
316
317/* Convert initial portion of wide string NPTR to `unsigned long long int'
318 representation. */
7782d0bf 319__extension__
2f6d1f1b
UD
320extern unsigned long long int wcstouq __P ((__const wchar_t *__restrict __nptr,
321 wchar_t **__restrict __endptr,
322 int __base));
75cd5204
RM
323#endif /* GCC and use GNU. */
324
2f6d1f1b
UD
325#if defined __USE_ISOC9X || (defined __GNUC__ && defined __USE_GNU)
326/* Convert initial portion of wide string NPTR to `long int'
327 representation. */
7782d0bf 328__extension__
2f6d1f1b
UD
329extern long long int wcstoll __P ((__const wchar_t *__restrict __nptr,
330 wchar_t **__restrict __endptr, int __base));
331
332/* Convert initial portion of wide string NPTR to `unsigned long long int'
333 representation. */
7782d0bf 334__extension__
2f6d1f1b
UD
335extern unsigned long long int wcstoull __P ((__const wchar_t *
336 __restrict __nptr,
337 wchar_t **__restrict __endptr,
338 int __base));
339#endif /* ISO C 9X or GCC and GNU. */
340
0501d603
UD
341#ifdef __USE_GNU
342/* The concept of one static locale per category is not very well
343 thought out. Many applications will need to process its data using
344 information from several different locales. Another application is
345 the implementation of the internationalization handling in the
346 upcoming ISO C++ standard library. To support this another set of
347 the functions using locale data exist which have an additional
348 argument.
349
350 Attention: all these functions are *not* standardized in any form.
351 This is a proof-of-concept implementation. */
352
353/* Structure for reentrant locale using functions. This is an
354 (almost) opaque type for the user level programs. */
355# include <xlocale.h>
356
357/* Special versions of the functions above which take the locale to
358 use as an additional parameter. */
359extern long int __wcstol_l __P ((__const wchar_t *__restrict __nptr,
360 wchar_t **__restrict __endptr, int __base,
361 __locale_t __loc));
362
363extern unsigned long int __wcstoul_l __P ((__const wchar_t *__restrict __nptr,
364 wchar_t **__restrict __endptr,
365 int __base, __locale_t __loc));
366
7782d0bf 367__extension__
0501d603
UD
368extern long long int __wcstoll_l __P ((__const wchar_t *__restrict __nptr,
369 wchar_t **__restrict __endptr,
370 int __base, __locale_t __loc));
371
7782d0bf 372__extension__
0501d603
UD
373extern unsigned long long int __wcstoull_l __P ((__const wchar_t *__restrict
374 __nptr,
375 wchar_t **__restrict __endptr,
376 int __base,
377 __locale_t __loc));
378
379extern double __wcstod_l __P ((__const wchar_t *__restrict __nptr,
380 wchar_t **__restrict __endptr,
381 __locale_t __loc));
382
383extern float __wcstof_l __P ((__const wchar_t *__restrict __nptr,
384 wchar_t **__restrict __endptr,
385 __locale_t __loc));
386
387extern __long_double_t __wcstold_l __P ((__const wchar_t *__restrict __nptr,
388 wchar_t **__restrict __endptr,
389 __locale_t __loc));
390#endif /* GNU */
391
75cd5204
RM
392
393/* The internal entry points for `wcstoX' take an extra flag argument
394 saying whether or not to parse locale-dependent number grouping. */
2f6d1f1b
UD
395extern double __wcstod_internal __P ((__const wchar_t *__restrict __nptr,
396 wchar_t **__restrict __endptr,
397 int __group));
398extern float __wcstof_internal __P ((__const wchar_t *__restrict __nptr,
399 wchar_t **__restrict __endptr,
400 int __group));
401extern __long_double_t __wcstold_internal __P ((__const wchar_t *
402 __restrict __nptr,
403 wchar_t **__restrict __endptr,
75cd5204
RM
404 int __group));
405
cc3fa755 406#ifndef __wcstol_internal_defined
2f6d1f1b
UD
407extern long int __wcstol_internal __P ((__const wchar_t *__restrict __nptr,
408 wchar_t **__restrict __endptr,
409 int __base, int __group));
cc3fa755
UD
410# define __wcstol_internal_defined 1
411#endif
412#ifndef __wcstoul_internal_defined
2f6d1f1b
UD
413extern unsigned long int __wcstoul_internal __P ((__const wchar_t *
414 __restrict __nptr,
415 wchar_t **
416 __restrict __endptr,
75cd5204 417 int __base, int __group));
cc3fa755
UD
418# define __wcstoul_internal_defined 1
419#endif
420#ifndef __wcstoll_internal_defined
7782d0bf 421__extension__
2f6d1f1b
UD
422extern long long int __wcstoll_internal __P ((__const wchar_t *
423 __restrict __nptr,
424 wchar_t **__restrict __endptr,
425 int __base, int __group));
cc3fa755
UD
426# define __wcstoll_internal_defined 1
427#endif
428#ifndef __wcstoull_internal_defined
7782d0bf 429__extension__
2f6d1f1b
UD
430extern unsigned long long int __wcstoull_internal __P ((__const wchar_t *
431 __restrict __nptr,
432 wchar_t **
433 __restrict __endptr,
434 int __base,
435 int __group));
cc3fa755
UD
436# define __wcstoull_internal_defined 1
437#endif
75cd5204
RM
438
439
dfd2257a 440#if defined __OPTIMIZE__ && __GNUC__ >= 2
75cd5204
RM
441/* Define inline functions which call the internal entry points. */
442
99e46354
UD
443extern __inline double wcstod (__const wchar_t *__restrict __nptr,
444 wchar_t **__restrict __endptr) __THROW
75cd5204 445{ return __wcstod_internal (__nptr, __endptr, 0); }
99e46354
UD
446extern __inline long int wcstol (__const wchar_t *__restrict __nptr,
447 wchar_t **__restrict __endptr,
448 int __base) __THROW
75cd5204 449{ return __wcstol_internal (__nptr, __endptr, __base, 0); }
99e46354
UD
450extern __inline unsigned long int wcstoul (__const wchar_t *__restrict __nptr,
451 wchar_t **__restrict __endptr,
452 int __base) __THROW
75cd5204
RM
453{ return __wcstoul_internal (__nptr, __endptr, __base, 0); }
454
dfd2257a 455# ifdef __USE_GNU
99e46354
UD
456extern __inline float wcstof (__const wchar_t *__restrict __nptr,
457 wchar_t **__restrict __endptr) __THROW
75cd5204 458{ return __wcstof_internal (__nptr, __endptr, 0); }
99e46354
UD
459extern __inline __long_double_t wcstold (__const wchar_t *__restrict __nptr,
460 wchar_t **__restrict __endptr) __THROW
75cd5204 461{ return __wcstold_internal (__nptr, __endptr, 0); }
75cd5204 462
57ba7bb4 463
7782d0bf 464__extension__
99e46354
UD
465extern __inline long long int wcstoq (__const wchar_t *__restrict __nptr,
466 wchar_t **__restrict __endptr,
467 int __base) __THROW
2f6d1f1b 468{ return __wcstoll_internal (__nptr, __endptr, __base, 0); }
7782d0bf 469__extension__
99e46354
UD
470extern __inline unsigned long long int wcstouq (__const wchar_t *
471 __restrict __nptr,
472 wchar_t **__restrict __endptr,
473 int __base) __THROW
2f6d1f1b 474{ return __wcstoull_internal (__nptr, __endptr, __base, 0); }
dfd2257a 475# endif /* Use GNU. */
75cd5204
RM
476#endif /* Optimizing GCC >=2. */
477
478
479#ifdef __USE_GNU
480/* Copy SRC to DEST, returning the address of the terminating L'\0' in
481 DEST. */
75cd5204
RM
482extern wchar_t *wcpcpy __P ((wchar_t *__dest, __const wchar_t *__src));
483
484/* Copy no more than N characters of SRC to DEST, returning the address of
485 the last character written into DEST. */
75cd5204
RM
486extern wchar_t *wcpncpy __P ((wchar_t *__dest, __const wchar_t *__src,
487 size_t __n));
488#endif /* use GNU */
489
490
9756dfe1
UD
491/* The X/Open standard demands that most of the functions defined in
492 the <wctype.h> header must also appear here. This is probably
493 because some X/Open members wrote their implementation before the
494 ISO C standard was published and introduced the better solution.
495 We have to provide these definitions for compliance reasons but we
496 do this nonsense only if really necessary. */
497#if defined __USE_UNIX98 && !defined __USE_GNU
498# define __need_iswxxx
499# include <wctype.h>
500#endif
501
30de3b18
RM
502__END_DECLS
503
504#endif /* wchar.h */