Update from main archive 961219
[glibc.git] / wcsmbs / wchar.h
blob689428bacffefdc31f33d8935c10e459ea88c473
1 /* Copyright (C) 1995, 1996 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 /* Duplicate S, returning an identical malloc'd string. */
93 extern wchar_t *wcsdup __P ((__const wchar_t *__s));
95 /* Find the first occurrence of WC in WCS. */
96 extern wchar_t *wcschr __P ((__const wchar_t *__wcs, wchar_t __wc));
97 /* Find the last occurrence of WC in WCS. */
98 extern wchar_t *wcsrchr __P ((__const wchar_t *__wcs, wchar_t __wc));
100 /* Return the length of the initial segmet of WCS which
101 consists entirely of wide-characters not in REJECT. */
102 extern size_t wcscspn __P ((__const wchar_t *__wcs,
103 __const wchar_t *__reject));
104 /* Return the length of the initial segmet of WCS which
105 consists entirely of wide-characters in ACCEPT. */
106 extern size_t wcsspn __P ((__const wchar_t *__wcs, __const wchar_t *__accept));
107 /* Find the first occurrence in WCS of any character in ACCEPT. */
108 extern wchar_t *wcspbrk __P ((__const wchar_t *__wcs,
109 __const wchar_t *__accept));
110 /* Find the first occurrence of NEEDLE in HAYSTACK. */
111 extern wchar_t *wcsstr __P ((__const wchar_t *__haystack,
112 __const wchar_t *__needle));
113 /* Divide WCS into tokens separated by characters in DELIM. */
114 extern wchar_t *wcstok __P ((wchar_t *__s, __const wchar_t *__delim,
115 wchar_t **ptr));
117 /* Return the number of wide-characters in S. */
118 extern size_t wcslen __P ((__const wchar_t *__s));
121 /* Search N bytes of S for C. */
122 extern wchar_t *wmemchr __P ((__const wchar_t *__s, wchar_t __c, size_t __n));
124 /* Compare N bytes of S1 and S2. */
125 extern int wmemcmp __P ((__const wchar_t *__s1, __const wchar_t *__s2,
126 size_t __n));
128 /* Copy N bytes of SRC to DEST. */
129 extern wchar_t *wmemcpy __P ((wchar_t *__s1, __const wchar_t *__s2,
130 size_t __n));
132 /* Copy N bytes of SRC to DEST, guaranteeing
133 correct behavior for overlapping strings. */
134 extern wchar_t *wmemmove __P ((wchar_t *__s1, __const wchar_t *__s2,
135 size_t __n));
137 /* Set N bytes of S to C. */
138 extern wchar_t *wmemset __P ((wchar_t *__s, wchar_t __c, size_t __n));
141 /* Determine whether C constitutes a valid (one-byte) multibyte
142 character. */
143 extern wint_t btowc __P ((int __c));
145 /* Determine whether C corresponds to a member of the extended
146 character set whose multibyte representation is a single byte. */
147 extern int wctob __P ((wint_t __c));
149 /* Determine whether PS points to an object representing the initial
150 state. */
151 extern int mbsinit __P ((__const mbstate_t *__ps));
153 /* Write wide character representation of multibyte character pointed
154 to by S to PWC. */
155 extern size_t __mbrtowc __P ((wchar_t *__pwc, __const char *__s, size_t __n,
156 mbstate_t *__p));
157 extern size_t mbrtowc __P ((wchar_t *__pwc, __const char *__s, size_t __n,
158 mbstate_t *__p));
160 /* Write multibyte representation of wide character WC to S. */
161 extern size_t __wcrtomb __P ((char *__s, wchar_t __wc, mbstate_t *__ps));
162 extern size_t wcrtomb __P ((char *__s, wchar_t __wc, mbstate_t *__ps));
164 /* Return number of bytes in multibyte character pointed to by S. */
165 extern size_t __mbrlen __P ((__const char *__s, size_t __n, mbstate_t *__ps));
166 extern size_t mbrlen __P ((__const char *__s, size_t __n, mbstate_t *__ps));
168 #if defined (__OPTIMIZE__) \
169 && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
170 /* Define inline function as optimization. */
171 extern __inline size_t mbrlen (__const char *s, size_t n, mbstate_t *ps)
172 { return ps != NULL ? __mbrtowc (NULL, s, n, ps) : __mbrlen (s, n, NULL); }
173 #endif
175 /* Write wide character representation of multibyte character string
176 SRC to DST. */
177 extern size_t __mbsrtowcs __P ((wchar_t *__dst, __const char **__src,
178 size_t __len, mbstate_t *__ps));
179 extern size_t mbsrtowcs __P ((wchar_t *__dst, __const char **__src,
180 size_t __len, mbstate_t *__ps));
182 /* Write multibyte character representation of wide character string
183 SRC to DST. */
184 extern size_t __wcsrtombs __P ((char *__dst, __const wchar_t **__src,
185 size_t __len, mbstate_t *__ps));
186 extern size_t wcsrtombs __P ((char *__dst, __const wchar_t **__src,
187 size_t __len, mbstate_t *__ps));
190 #ifdef __USE_GNU
191 /* Write wide character representation of at most NMC bytes of the
192 multibyte character string SRC to DST. */
193 extern size_t __mbsnrtowcs __P ((wchar_t *__dst, __const char **__src,
194 size_t __nmc, size_t __len, mbstate_t *__ps));
195 extern size_t mbsnrtowcs __P ((wchar_t *__dst, __const char **__src,
196 size_t __nmc, size_t __len, mbstate_t *__ps));
198 /* Write multibyte character representation of at most NWC characters
199 from the wide character string SRC to DST. */
200 extern size_t __wcsnrtombs __P ((char *__dst, __const wchar_t **__src,
201 size_t __nwc, size_t __len, mbstate_t *__ps));
202 extern size_t wcsnrtombs __P ((char *__dst, __const wchar_t **__src,
203 size_t __nwc, size_t __len, mbstate_t *__ps));
206 /* The following functions are extensions found in X/Open CAE. */
208 /* Determine number of column positions required for C. */
209 extern int wcwidth __P ((wint_t __c));
211 /* Determine number of column positions required for first N wide
212 characters (or fewer if S ends before this) in S. */
213 extern int wcswidth __P ((__const wchar_t *__s, size_t __n));
214 #endif /* use GNU */
217 /* Convert initial portion of the wide string NPTR to `double'
218 representation. */
219 extern double wcstod __P ((__const wchar_t *__nptr, wchar_t **__endptr));
221 #ifdef __USE_GNU
222 /* Likewise for `float' and `long double' sizes of floating-point numbers. */
223 extern float wcstof __P ((__const wchar_t *__nptr, wchar_t **__endptr));
224 extern __long_double_t wcstold __P ((__const wchar_t *__nptr,
225 wchar_t **__endptr));
226 #endif /* GNU */
229 /* Convert initial portion of wide string NPTR to `long int'
230 representation. */
231 extern long int wcstol __P ((__const wchar_t *__nptr, wchar_t **__endptr,
232 int __base));
234 /* Convert initial portion of wide string NPTR to `unsigned long int'
235 representation. */
236 extern unsigned long int wcstoul __P ((__const wchar_t *__nptr,
237 wchar_t **__endptr, int __base));
239 #if defined (__GNUC__) && defined (__USE_GNU)
240 /* Convert initial portion of wide string NPTR to `long int'
241 representation. */
242 extern long long int wcstoq __P ((__const wchar_t *__nptr, wchar_t **__endptr,
243 int __base));
245 /* Convert initial portion of wide string NPTR to `unsigned long long int'
246 representation. */
247 extern unsigned long long int wcstouq __P ((__const wchar_t *__nptr,
248 wchar_t **__endptr, int __base));
249 #endif /* GCC and use GNU. */
252 /* The internal entry points for `wcstoX' take an extra flag argument
253 saying whether or not to parse locale-dependent number grouping. */
254 extern double __wcstod_internal __P ((__const wchar_t *__nptr,
255 wchar_t **__endptr, int __group));
256 extern float __wcstof_internal __P ((__const wchar_t *__nptr,
257 wchar_t **__endptr, int __group));
258 extern __long_double_t __wcstold_internal __P ((__const wchar_t *__nptr,
259 wchar_t **__endptr,
260 int __group));
262 extern long int __wcstol_internal __P ((__const wchar_t *__nptr,
263 wchar_t **__endptr, int __base,
264 int __group));
265 extern unsigned long int __wcstoul_internal __P ((__const wchar_t *__nptr,
266 wchar_t **__endptr,
267 int __base, int __group));
268 #if defined __GNUC__ && defined __USE_GNU
269 extern long long int __wcstoq_internal __P ((__const wchar_t *__nptr,
270 wchar_t **__endptr, int __base,
271 int __group));
272 extern unsigned long long int __wcstouq_internal __P ((__const wchar_t *__nptr,
273 wchar_t **__endptr,
274 int __base,
275 int __group));
276 #endif /* GCC and use GNU. */
279 #if defined (__OPTIMIZE__) && __GNUC__ >= 2
280 /* Define inline functions which call the internal entry points. */
282 extern __inline double wcstod (__const wchar_t *__nptr, wchar_t **__endptr)
283 { return __wcstod_internal (__nptr, __endptr, 0); }
284 extern __inline long int wcstol (__const wchar_t *__nptr,
285 wchar_t **__endptr, int __base)
286 { return __wcstol_internal (__nptr, __endptr, __base, 0); }
287 extern __inline unsigned long int wcstoul (__const wchar_t *__nptr,
288 wchar_t **__endptr, int __base)
289 { return __wcstoul_internal (__nptr, __endptr, __base, 0); }
291 #ifdef __USE_GNU
292 extern __inline float wcstof (__const wchar_t *__nptr, wchar_t **__endptr)
293 { return __wcstof_internal (__nptr, __endptr, 0); }
294 extern __inline __long_double_t wcstold (__const wchar_t *__nptr,
295 wchar_t **__endptr)
296 { return __wcstold_internal (__nptr, __endptr, 0); }
299 extern __inline long long int wcstoq (__const wchar_t *__nptr,
300 wchar_t **__endptr, int __base)
301 { return __wcstoq_internal (__nptr, __endptr, __base, 0); }
302 extern __inline unsigned long long int wcstouq (__const wchar_t *__nptr,
303 wchar_t **__endptr, int __base)
304 { return __wcstouq_internal (__nptr, __endptr, __base, 0); }
305 #endif /* Use GNU. */
306 #endif /* Optimizing GCC >=2. */
309 #ifdef __USE_GNU
310 /* Copy SRC to DEST, returning the address of the terminating L'\0' in
311 DEST. */
312 extern wchar_t *__wcpcpy __P ((wchar_t *__dest, __const wchar_t *__src));
313 extern wchar_t *wcpcpy __P ((wchar_t *__dest, __const wchar_t *__src));
315 /* Copy no more than N characters of SRC to DEST, returning the address of
316 the last character written into DEST. */
317 extern wchar_t *__wcpncpy __P ((wchar_t *__dest, __const wchar_t *__src,
318 size_t __n));
319 extern wchar_t *wcpncpy __P ((wchar_t *__dest, __const wchar_t *__src,
320 size_t __n));
321 #endif /* use GNU */
324 __END_DECLS
326 #endif /* wchar.h */