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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
20 * ISO Standard: 7.16.4 General wide-string utilities <wchar.h>
30 /* Get size_t, wchar_t, wint_t and NULL from <stddef.h>. */
32 #define __need_wchar_t
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. */
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. */
46 typedef unsigned int wint_t;
50 /* Conversion state information. */
53 int count
; /* Number of bytes needed for the current character. */
54 wint_t value
; /* Value so far. */
57 #define WCHAR_MIN ((wchar_t) 0)
58 #define WCHAR_MAX (~WCHAR_MIN)
61 # define WEOF (0xffffffffu)
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
,
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
,
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
,
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
));
91 /* Duplicate S, returning an identical malloc'd string. */
92 extern wchar_t *wcsdup
__P ((__const
wchar_t *__s
));
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
));
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
,
116 /* Return the number of wide-characters in S. */
117 extern size_t wcslen
__P ((__const
wchar_t *__s
));
120 /* Search N bytes of S for C. */
121 extern wchar_t *wmemchr
__P ((__const
wchar_t *__s
, wchar_t __c
, size_t __n
));
123 /* Compare N bytes of S1 and S2. */
124 extern int wmemcmp
__P ((__const
wchar_t *__s1
, __const
wchar_t *__s2
,
127 /* Copy N bytes of SRC to DEST. */
128 extern wchar_t *wmemcpy
__P ((wchar_t *__s1
, __const
wchar_t *__s2
,
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
,
136 /* Set N bytes of S to C. */
137 extern wchar_t *wmemset
__P ((wchar_t *__s
, wchar_t __c
, size_t __n
));
140 /* Determine whether C constitutes a valid (one-byte) multibyte
142 extern wint_t btowc
__P ((int __c
));
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
));
148 /* Determine whether PS points to an object representing the initial
150 extern int mbsinit
__P ((__const
mbstate_t *__ps
));
152 /* Write wide character representation of multibyte character pointed
154 extern size_t __mbrtowc
__P ((wchar_t *__pwc
, __const
char *__s
, size_t __n
,
156 extern size_t mbrtowc
__P ((wchar_t *__pwc
, __const
char *__s
, size_t __n
,
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
));
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
));
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
); }
174 /* Write wide character representation of multibyte character string
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
));
181 /* Write multibyte character representation of wide character string
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
));
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
));
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
));
205 /* The following functions are extensions found in X/Open CAE. */
207 /* Determine number of column positions required for C. */
208 extern int wcwidth
__P ((wint_t __c
));
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
));
216 /* Convert initial portion of the wide string NPTR to `double'
218 extern double wcstod
__P ((__const
wchar_t *__nptr
, wchar_t **__endptr
));
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
));
228 /* Convert initial portion of wide string NPTR to `long int'
230 extern long int wcstol
__P ((__const
wchar_t *__nptr
, wchar_t **__endptr
,
233 /* Convert initial portion of wide string NPTR to `unsigned long int'
235 extern unsigned long int wcstoul
__P ((__const
wchar_t *__nptr
,
236 wchar_t **__endptr
, int __base
));
238 #if defined (__GNUC__) && defined (__USE_GNU)
239 /* Convert initial portion of wide string NPTR to `long int'
241 extern long long int wcstoq
__P ((__const
wchar_t *__nptr
, wchar_t **__endptr
,
244 /* Convert initial portion of wide string NPTR to `unsigned long long int'
246 extern unsigned long long int wcstouq
__P ((__const
wchar_t *__nptr
,
247 wchar_t **__endptr
, int __base
));
248 #endif /* GCC and use GNU. */
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
,
261 extern long int __wcstol_internal
__P ((__const
wchar_t *__nptr
,
262 wchar_t **__endptr
, int __base
,
264 extern unsigned long int __wcstoul_internal
__P ((__const
wchar_t *__nptr
,
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
,
271 extern unsigned long long int __wcstouq_internal
__P ((__const
wchar_t *__nptr
,
275 #endif /* GCC and use GNU. */
278 #if defined (__OPTIMIZE__) && __GNUC__ >= 2
279 /* Define inline functions which call the internal entry points. */
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); }
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
,
295 { return __wcstold_internal (__nptr
, __endptr
, 0); }
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. */
309 /* Copy SRC to DEST, returning the address of the terminating L'\0' in
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
));
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
,
318 extern wchar_t *wcpncpy
__P ((wchar_t *__dest
, __const
wchar_t *__src
,