Update to 2.1.x development version
[glibc.git] / wcsmbs / wchar.h
blob597a03d735f0bf53a33478d9e4c9cd14787d0bc0
1 /* Copyright (C) 1995, 1996, 1997 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
26 #define _WCHAR_H 1
27 #include <features.h>
29 __BEGIN_DECLS
31 /* Get size_t, wchar_t, wint_t and NULL from <stddef.h>. */
32 #define __need_size_t
33 #define __need_wchar_t
34 #define __need_wint_t
35 #define __need_NULL
36 #include <stddef.h>
39 /* We try to get wint_t from <stddef.h>, but not all GCC versions define it
40 there. So define it ourselves if it remains undefined. */
41 #ifndef _WINT_T
42 /* Integral type unchanged by default argument promotions that can
43 hold any value corresponding to members of the extended character
44 set, as well as at least one value that does not correspond to any
45 member of the extended character set. */
46 #define _WINT_T
47 typedef unsigned int wint_t;
48 #endif
51 /* Conversion state information. */
52 typedef struct
54 int count; /* Number of bytes needed for the current character. */
55 wint_t value; /* Value so far. */
56 } mbstate_t;
58 #define WCHAR_MIN ((wchar_t) 0)
59 #define WCHAR_MAX (~WCHAR_MIN)
61 #ifndef WEOF
62 # define WEOF (0xffffffffu)
63 #endif
66 /* Copy SRC to DEST. */
67 extern wchar_t *wcscpy __P ((wchar_t *__dest, __const wchar_t *__src));
68 /* Copy no more than N wide-characters of SRC to DEST. */
69 extern wchar_t *wcsncpy __P ((wchar_t *__dest, __const wchar_t *__src,
70 size_t __n));
72 /* Append SRC onto DEST. */
73 extern wchar_t *wcscat __P ((wchar_t *__dest, __const wchar_t *__src));
74 /* Append no more than N wide-characters of SRC onto DEST. */
75 extern wchar_t *wcsncat __P ((wchar_t *__dest, __const wchar_t *__src,
76 size_t __n));
78 /* Compare S1 and S2. */
79 extern int wcscmp __P ((__const wchar_t *__s1, __const wchar_t *__s2));
80 /* Compare N wide-characters of S1 and S2. */
81 extern int wcsncmp __P ((__const wchar_t *__s1, __const wchar_t *__s2,
82 size_t __n));
84 /* Compare S1 and S2, both interpreted as appropriate to the
85 LC_COLLATE category of the current locale. */
86 extern int wcscoll __P ((__const wchar_t *__s1, __const wchar_t *__s2));
87 /* Transform S2 into array pointed to by S1 such that if wcscmp is
88 applied to two transformed strings the result is the as applying
89 `wcscoll' to the original strings. */
90 extern size_t wcsxfrm __P ((wchar_t *__s1, __const wchar_t *__s2, size_t __n));
92 #ifdef __USE_GNU
93 /* Similar to the two functions above but take the information from
94 the provided locale and not the global locale. */
95 # include <xlocale.h>
97 /* Compare S1 and S2, both interpreted as appropriate to the
98 LC_COLLATE category of the given locale. */
99 extern int __wcscoll_l __P ((__const wchar_t *__s1, __const wchar_t *__s2,
100 __locale_t loc));
101 /* Transform S2 into array pointed to by S1 such that if wcscmp is
102 applied to two transformed strings the result is the as applying
103 `wcscoll' to the original strings. */
104 extern size_t __wcsxfrm_l __P ((wchar_t *__s1, __const wchar_t *__s2,
105 size_t __n, __locale_t loc));
106 #endif
108 /* Duplicate S, returning an identical malloc'd string. */
109 extern wchar_t *wcsdup __P ((__const wchar_t *__s));
111 /* Find the first occurrence of WC in WCS. */
112 extern wchar_t *wcschr __P ((__const wchar_t *__wcs, wchar_t __wc));
113 /* Find the last occurrence of WC in WCS. */
114 extern wchar_t *wcsrchr __P ((__const wchar_t *__wcs, wchar_t __wc));
116 /* Return the length of the initial segmet of WCS which
117 consists entirely of wide-characters not in REJECT. */
118 extern size_t wcscspn __P ((__const wchar_t *__wcs,
119 __const wchar_t *__reject));
120 /* Return the length of the initial segmet of WCS which
121 consists entirely of wide-characters in ACCEPT. */
122 extern size_t wcsspn __P ((__const wchar_t *__wcs, __const wchar_t *__accept));
123 /* Find the first occurrence in WCS of any character in ACCEPT. */
124 extern wchar_t *wcspbrk __P ((__const wchar_t *__wcs,
125 __const wchar_t *__accept));
126 /* Find the first occurrence of NEEDLE in HAYSTACK. */
127 extern wchar_t *wcsstr __P ((__const wchar_t *__haystack,
128 __const wchar_t *__needle));
129 /* Divide WCS into tokens separated by characters in DELIM. */
130 extern wchar_t *wcstok __P ((wchar_t *__s, __const wchar_t *__delim,
131 wchar_t **ptr));
133 /* Return the number of wide-characters in S. */
134 extern size_t wcslen __P ((__const wchar_t *__s));
137 /* Search N bytes of S for C. */
138 extern wchar_t *wmemchr __P ((__const wchar_t *__s, wchar_t __c, size_t __n));
140 /* Compare N bytes of S1 and S2. */
141 extern int wmemcmp __P ((__const wchar_t *__s1, __const wchar_t *__s2,
142 size_t __n));
144 /* Copy N bytes of SRC to DEST. */
145 extern wchar_t *wmemcpy __P ((wchar_t *__s1, __const wchar_t *__s2,
146 size_t __n));
148 /* Copy N bytes of SRC to DEST, guaranteeing
149 correct behavior for overlapping strings. */
150 extern wchar_t *wmemmove __P ((wchar_t *__s1, __const wchar_t *__s2,
151 size_t __n));
153 /* Set N bytes of S to C. */
154 extern wchar_t *wmemset __P ((wchar_t *__s, wchar_t __c, size_t __n));
157 /* Determine whether C constitutes a valid (one-byte) multibyte
158 character. */
159 extern wint_t btowc __P ((int __c));
161 /* Determine whether C corresponds to a member of the extended
162 character set whose multibyte representation is a single byte. */
163 extern int wctob __P ((wint_t __c));
165 /* Determine whether PS points to an object representing the initial
166 state. */
167 extern int mbsinit __P ((__const mbstate_t *__ps));
169 /* Write wide character representation of multibyte character pointed
170 to by S to PWC. */
171 extern size_t __mbrtowc __P ((wchar_t *__pwc, __const char *__s, size_t __n,
172 mbstate_t *__p));
173 extern size_t mbrtowc __P ((wchar_t *__pwc, __const char *__s, size_t __n,
174 mbstate_t *__p));
176 /* Write multibyte representation of wide character WC to S. */
177 extern size_t __wcrtomb __P ((char *__s, wchar_t __wc, mbstate_t *__ps));
178 extern size_t wcrtomb __P ((char *__s, wchar_t __wc, mbstate_t *__ps));
180 /* Return number of bytes in multibyte character pointed to by S. */
181 extern size_t __mbrlen __P ((__const char *__s, size_t __n, mbstate_t *__ps));
182 extern size_t mbrlen __P ((__const char *__s, size_t __n, mbstate_t *__ps));
184 #if defined (__OPTIMIZE__) \
185 && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
186 /* Define inline function as optimization. */
187 extern __inline size_t mbrlen (__const char *s, size_t n, mbstate_t *ps)
188 { return ps != NULL ? __mbrtowc (NULL, s, n, ps) : __mbrlen (s, n, NULL); }
189 #endif
191 /* Write wide character representation of multibyte character string
192 SRC to DST. */
193 extern size_t __mbsrtowcs __P ((wchar_t *__dst, __const char **__src,
194 size_t __len, mbstate_t *__ps));
195 extern size_t mbsrtowcs __P ((wchar_t *__dst, __const char **__src,
196 size_t __len, mbstate_t *__ps));
198 /* Write multibyte character representation of wide character string
199 SRC to DST. */
200 extern size_t __wcsrtombs __P ((char *__dst, __const wchar_t **__src,
201 size_t __len, mbstate_t *__ps));
202 extern size_t wcsrtombs __P ((char *__dst, __const wchar_t **__src,
203 size_t __len, mbstate_t *__ps));
206 #ifdef __USE_GNU
207 /* Write wide character representation of at most NMC bytes of the
208 multibyte character string SRC to DST. */
209 extern size_t __mbsnrtowcs __P ((wchar_t *__dst, __const char **__src,
210 size_t __nmc, size_t __len, mbstate_t *__ps));
211 extern size_t mbsnrtowcs __P ((wchar_t *__dst, __const char **__src,
212 size_t __nmc, size_t __len, mbstate_t *__ps));
214 /* Write multibyte character representation of at most NWC characters
215 from the wide character string SRC to DST. */
216 extern size_t __wcsnrtombs __P ((char *__dst, __const wchar_t **__src,
217 size_t __nwc, size_t __len, mbstate_t *__ps));
218 extern size_t wcsnrtombs __P ((char *__dst, __const wchar_t **__src,
219 size_t __nwc, size_t __len, mbstate_t *__ps));
222 /* The following functions are extensions found in X/Open CAE. */
224 /* Determine number of column positions required for C. */
225 extern int wcwidth __P ((wint_t __c));
227 /* Determine number of column positions required for first N wide
228 characters (or fewer if S ends before this) in S. */
229 extern int wcswidth __P ((__const wchar_t *__s, size_t __n));
230 #endif /* use GNU */
233 /* Convert initial portion of the wide string NPTR to `double'
234 representation. */
235 extern double wcstod __P ((__const wchar_t *__nptr, wchar_t **__endptr));
237 #ifdef __USE_GNU
238 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
239 extern float wcstof __P ((__const wchar_t *__nptr, wchar_t **__endptr));
240 extern __long_double_t wcstold __P ((__const wchar_t *__nptr,
241 wchar_t **__endptr));
242 #endif /* GNU */
245 /* Convert initial portion of wide string NPTR to `long int'
246 representation. */
247 extern long int wcstol __P ((__const wchar_t *__nptr, wchar_t **__endptr,
248 int __base));
250 /* Convert initial portion of wide string NPTR to `unsigned long int'
251 representation. */
252 extern unsigned long int wcstoul __P ((__const wchar_t *__nptr,
253 wchar_t **__endptr, int __base));
255 #if defined (__GNUC__) && defined (__USE_GNU)
256 /* Convert initial portion of wide string NPTR to `long int'
257 representation. */
258 extern long long int wcstoq __P ((__const wchar_t *__nptr, wchar_t **__endptr,
259 int __base));
261 /* Convert initial portion of wide string NPTR to `unsigned long long int'
262 representation. */
263 extern unsigned long long int wcstouq __P ((__const wchar_t *__nptr,
264 wchar_t **__endptr, int __base));
265 #endif /* GCC and use GNU. */
268 /* The internal entry points for `wcstoX' take an extra flag argument
269 saying whether or not to parse locale-dependent number grouping. */
270 extern double __wcstod_internal __P ((__const wchar_t *__nptr,
271 wchar_t **__endptr, int __group));
272 extern float __wcstof_internal __P ((__const wchar_t *__nptr,
273 wchar_t **__endptr, int __group));
274 extern __long_double_t __wcstold_internal __P ((__const wchar_t *__nptr,
275 wchar_t **__endptr,
276 int __group));
278 extern long int __wcstol_internal __P ((__const wchar_t *__nptr,
279 wchar_t **__endptr, int __base,
280 int __group));
281 extern unsigned long int __wcstoul_internal __P ((__const wchar_t *__nptr,
282 wchar_t **__endptr,
283 int __base, int __group));
284 #if defined __GNUC__ && defined __USE_GNU
285 extern long long int __wcstoq_internal __P ((__const wchar_t *__nptr,
286 wchar_t **__endptr, int __base,
287 int __group));
288 extern unsigned long long int __wcstouq_internal __P ((__const wchar_t *__nptr,
289 wchar_t **__endptr,
290 int __base,
291 int __group));
292 #endif /* GCC and use GNU. */
295 #if defined (__OPTIMIZE__) && __GNUC__ >= 2
296 /* Define inline functions which call the internal entry points. */
298 extern __inline double wcstod (__const wchar_t *__nptr, wchar_t **__endptr)
299 { return __wcstod_internal (__nptr, __endptr, 0); }
300 extern __inline long int wcstol (__const wchar_t *__nptr,
301 wchar_t **__endptr, int __base)
302 { return __wcstol_internal (__nptr, __endptr, __base, 0); }
303 extern __inline unsigned long int wcstoul (__const wchar_t *__nptr,
304 wchar_t **__endptr, int __base)
305 { return __wcstoul_internal (__nptr, __endptr, __base, 0); }
307 #ifdef __USE_GNU
308 extern __inline float wcstof (__const wchar_t *__nptr, wchar_t **__endptr)
309 { return __wcstof_internal (__nptr, __endptr, 0); }
310 extern __inline __long_double_t wcstold (__const wchar_t *__nptr,
311 wchar_t **__endptr)
312 { return __wcstold_internal (__nptr, __endptr, 0); }
315 extern __inline long long int wcstoq (__const wchar_t *__nptr,
316 wchar_t **__endptr, int __base)
317 { return __wcstoq_internal (__nptr, __endptr, __base, 0); }
318 extern __inline unsigned long long int wcstouq (__const wchar_t *__nptr,
319 wchar_t **__endptr, int __base)
320 { return __wcstouq_internal (__nptr, __endptr, __base, 0); }
321 #endif /* Use GNU. */
322 #endif /* Optimizing GCC >=2. */
325 #ifdef __USE_GNU
326 /* Copy SRC to DEST, returning the address of the terminating L'\0' in
327 DEST. */
328 extern wchar_t *__wcpcpy __P ((wchar_t *__dest, __const wchar_t *__src));
329 extern wchar_t *wcpcpy __P ((wchar_t *__dest, __const wchar_t *__src));
331 /* Copy no more than N characters of SRC to DEST, returning the address of
332 the last character written into DEST. */
333 extern wchar_t *__wcpncpy __P ((wchar_t *__dest, __const wchar_t *__src,
334 size_t __n));
335 extern wchar_t *wcpncpy __P ((wchar_t *__dest, __const wchar_t *__src,
336 size_t __n));
337 #endif /* use GNU */
340 __END_DECLS
342 #endif /* wchar.h */