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