OSDN Git Service

ctype.c, _collate.c, str[n]casecmp.c, strlcpy.c: remove unused hidden functions
[uclinux-h8/uClibc.git] / include / ctype.h
1 /* Copyright (C) 1991,92,93,95,96,97,98,99,2001,02
2         Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 /*
21  *      ISO C99 Standard 7.4: Character handling        <ctype.h>
22  */
23
24 #ifndef _CTYPE_H
25 #define _CTYPE_H        1
26
27 #include <features.h>
28 #include <bits/types.h>
29
30 __BEGIN_DECLS
31 __BEGIN_NAMESPACE_STD
32
33 /* The following names are all functions:
34      int isCHARACTERISTIC(int c);
35    which return nonzero iff C has CHARACTERISTIC.
36    For the meaning of the characteristic names, see the `enum' above.  */
37 extern int isalnum(int __c) __THROW;
38 libc_hidden_proto(isalnum)
39 extern int isalpha(int __c) __THROW;
40 libc_hidden_proto(isalpha)
41 extern int iscntrl(int __c) __THROW;
42 libc_hidden_proto(iscntrl)
43 extern int isdigit(int __c) __THROW;
44 libc_hidden_proto(isdigit)
45 extern int islower(int __c) __THROW;
46 libc_hidden_proto(islower)
47 extern int isgraph(int __c) __THROW;
48 libc_hidden_proto(isgraph)
49 extern int isprint(int __c) __THROW;
50 libc_hidden_proto(isprint)
51 extern int ispunct(int __c) __THROW;
52 libc_hidden_proto(ispunct)
53 extern int isspace(int __c) __THROW;
54 libc_hidden_proto(isspace)
55 extern int isupper(int __c) __THROW;
56 libc_hidden_proto(isupper)
57 extern int isxdigit(int __c) __THROW;
58 libc_hidden_proto(isxdigit)
59
60
61 /* Return the lowercase version of C.  */
62 extern int tolower(int __c) __THROW;
63 libc_hidden_proto(tolower)
64
65 /* Return the uppercase version of C.  */
66 extern int toupper(int __c) __THROW;
67 libc_hidden_proto(toupper)
68
69 #if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) && \
70         defined __UCLIBC_SUSV4_LEGACY__
71 /* Return nonzero iff C is in the ASCII set
72    (i.e., is no more than 7 bits wide).  */
73 extern int isascii(int __c) __THROW;
74 libc_hidden_proto(isascii)
75 /* Return the part of C that is in the ASCII set
76    (i.e., the low-order 7 bits of C).  */
77 extern int toascii(int __c) __THROW;
78 #endif
79
80 __END_NAMESPACE_STD
81
82
83 /* ISO C99 introduced one new function.  */
84 #ifdef  __USE_ISOC99
85 __BEGIN_NAMESPACE_C99
86
87 extern int isblank(int __c) __THROW;
88 libc_hidden_proto(isblank)
89
90 __END_NAMESPACE_C99
91 #endif
92 __END_DECLS
93
94 #ifndef __UCLIBC_HAS_CTYPE_TABLES__
95
96 /* "Stub locale": we are permanently in C/POSIX locale.
97  * Using simple(r) ctype.h machinery in this header instead: */
98 #include <bits/uClibc_ctype.h>
99
100 #else
101
102 __BEGIN_DECLS
103
104 #ifndef _ISbit
105 /* These are all the characteristics of characters.
106    If there get to be more than 16 distinct characteristics,
107    __ctype_mask_t will need to be adjusted. */
108
109 /* libstdc++ from gcc toolchain needs this macro. */
110 # define _ISbit(bit)    (1 << (bit))
111
112 enum
113 {
114   _ISupper = _ISbit (0),        /* UPPERCASE.  */
115   _ISlower = _ISbit (1),        /* lowercase.  */
116   _ISalpha = _ISbit (2),        /* Alphabetic.  */
117   _ISdigit = _ISbit (3),        /* Numeric.  */
118   _ISxdigit = _ISbit (4),       /* Hexadecimal numeric.  */
119   _ISspace = _ISbit (5),        /* Whitespace.  */
120   _ISprint = _ISbit (6),        /* Printing.  */
121   _ISgraph = _ISbit (7),        /* Graphical.  */
122   _ISblank = _ISbit (8),        /* Blank (usually SPC and TAB).  */
123   _IScntrl = _ISbit (9),        /* Control character.  */
124   _ISpunct = _ISbit (10),       /* Punctuation.  */
125   _ISalnum = _ISbit (11)        /* Alphanumeric.  */
126 };
127 #else
128 #error _ISbit already defined!
129 #endif /* ! _ISbit  */
130
131 /* __ctype_XXX_t types and __UCLIBC_CTYPE_x_TBL_OFFSET constants */
132 #include <bits/uClibc_touplow.h>
133
134 #ifdef __UCLIBC_HAS_CTYPE_SIGNED__
135 # define __UCLIBC_CTYPE_IN_TO_DOMAIN(c) (((unsigned int)((c) + 128)) < 384)
136 #else
137 # define __UCLIBC_CTYPE_IN_TO_DOMAIN(c) (((unsigned int)(c)) < 256)
138 #endif
139
140 /* In the thread-specific locale model (see `uselocale' in <locale.h>)
141    we cannot use global variables for these as was done in the past.
142    Instead, the following accessor functions return the address of
143    each variable, which is local to the current thread if multithreaded.
144
145    These point into arrays of 384, so they can be indexed by any `unsigned
146    char' value [0,255]; by EOF (-1); or by any `signed char' value
147    [-128,-1).  ISO C requires that the ctype functions work for `unsigned
148    char' values and for EOF; we also support negative `signed char' values
149    for broken old programs.  The case conversion arrays are of `int's
150    rather than `unsigned char's because tolower (EOF) must be EOF, which
151    doesn't fit into an `unsigned char'.  But today more important is that
152    the arrays are also used for multi-byte character sets.  */
153
154 /* uClibc differences:
155  *
156  * When __UCLIBC_HAS_CTYPE_SIGNED is defined,
157  *
158  *    The upper and lower mapping arrays are type int16_t, so that
159  *    they may store all char values plus EOF.  The glibc reasoning
160  *    given above for these being type int is questionable, as the
161  *    ctype mapping functions map from the set of (unsigned) char
162  *    and EOF back into the set.  They have no awareness of multi-byte
163  *    or wide characters.
164  *
165  * Otherwise,
166  *
167  *    The ctype array is defined for -1..255.
168  *    The upper and lower mapping arrays are defined for 0..255.
169  *    The upper and lower mapping arrays are type unsigned char.
170  */
171
172 /* Pointers to the default C-locale data. */
173 extern const __ctype_mask_t *__C_ctype_b;
174 libc_hidden_proto(__C_ctype_b)
175 extern const __ctype_touplow_t *__C_ctype_toupper;
176 libc_hidden_proto(__C_ctype_toupper)
177 extern const __ctype_touplow_t *__C_ctype_tolower;
178 libc_hidden_proto(__C_ctype_tolower)
179
180 #ifdef __UCLIBC_HAS_XLOCALE__
181
182 const __ctype_mask_t **__ctype_b_loc(void) __attribute__ ((const));
183 libc_hidden_proto(__ctype_b_loc)
184 const __ctype_touplow_t **__ctype_tolower_loc(void) __attribute__ ((const));
185 libc_hidden_proto(__ctype_tolower_loc)
186 const __ctype_touplow_t **__ctype_toupper_loc(void) __attribute__ ((const));
187 libc_hidden_proto(__ctype_toupper_loc)
188 #define __UCLIBC_CTYPE_B        (*__ctype_b_loc())
189 #define __UCLIBC_CTYPE_TOLOWER  (*__ctype_tolower_loc())
190 #define __UCLIBC_CTYPE_TOUPPER  (*__ctype_toupper_loc())
191
192 #else  /* __UCLIBC_HAS_XLOCALE__ */
193
194 /* Pointers to the current global locale data in use. */
195 extern const __ctype_mask_t *__ctype_b;
196 libc_hidden_proto(__ctype_b)
197 extern const __ctype_touplow_t *__ctype_toupper;
198 libc_hidden_proto(__ctype_toupper)
199 extern const __ctype_touplow_t *__ctype_tolower;
200 libc_hidden_proto(__ctype_tolower)
201 #define __UCLIBC_CTYPE_B        (__ctype_b)
202 #define __UCLIBC_CTYPE_TOLOWER  (__ctype_tolower)
203 #define __UCLIBC_CTYPE_TOUPPER  (__ctype_toupper)
204
205 #endif /* __UCLIBC_HAS_XLOCALE__ */
206
207 #ifdef __UCLIBC_SUSV4_LEGACY__
208 #define __isascii(c)    (((c) & ~0x7f) == 0)    /* If C is a 7 bit value.  */
209 #define __toascii(c)    ((c) & 0x7f)            /* Mask off high bits.  */
210 #endif
211
212 #ifdef _LIBC
213 /* These are uClibc-specific. */
214 #define __isdigit_char(C)    (((unsigned char)((C) - '0')) <= 9)
215 #define __isdigit_int(C)     (((unsigned int)((C) - '0')) <= 9)
216 #endif
217
218 #ifdef __USE_GNU
219 /* Test C for a set of character classes according to MASK.  */
220 extern int isctype(int __c, int __mask) __THROW;
221 #endif
222
223 #if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
224         && defined __UCLIBC_SUSV4_LEGACY__
225 /* These are the same as `toupper' and `tolower' except that they do not
226    check the argument for being in the range of a `char'.  */
227 extern int _toupper(int __c) __THROW;
228 extern int _tolower(int __c) __THROW;
229 #endif /* Use SVID or use misc.  */
230
231 /* This code is needed for the optimized mapping functions.  */
232 #define __tobody(c, f, table, args) \
233 (__extension__ ({ \
234         int __res; \
235         if (sizeof(c) > 1) { \
236                 if (__builtin_constant_p(c)) { \
237                         int __c = (c); \
238                         __res = __UCLIBC_CTYPE_IN_TO_DOMAIN(__c) ? (table)[__c] : __c; \
239                 } else \
240                         __res = f args; \
241         } else \
242                 __res = (table)[(int) (c)]; \
243         __res; \
244 }))
245
246 #define __isctype(c, type) ((__UCLIBC_CTYPE_B)[(int)(c)] & (__ctype_mask_t)type)
247 /* Do not combine in one #if - unifdef tool is not that clever */
248 #ifndef __NO_CTYPE
249 #ifndef __cplusplus
250 # define isalnum(c)     __isctype((c), _ISalnum)
251 # define isalpha(c)     __isctype((c), _ISalpha)
252 # define iscntrl(c)     __isctype((c), _IScntrl)
253 # define isdigit(c)     __isctype((c), _ISdigit)
254 # define islower(c)     __isctype((c), _ISlower)
255 # define isgraph(c)     __isctype((c), _ISgraph)
256 # define isprint(c)     __isctype((c), _ISprint)
257 # define ispunct(c)     __isctype((c), _ISpunct)
258 # define isspace(c)     __isctype((c), _ISspace)
259 # define isupper(c)     __isctype((c), _ISupper)
260 # define isxdigit(c)    __isctype((c), _ISxdigit)
261 # ifdef __USE_ISOC99
262 #  define isblank(c)    __isctype((c), _ISblank)
263 # endif
264
265 # ifdef __USE_EXTERN_INLINES
266 __extern_inline int
267 __NTH (tolower (int __c))
268 {
269   return __UCLIBC_CTYPE_IN_TO_DOMAIN(__c) ? (__UCLIBC_CTYPE_TOLOWER)[__c] : __c;
270 }
271 __extern_inline int
272 __NTH (toupper (int __c))
273 {
274   return __UCLIBC_CTYPE_IN_TO_DOMAIN(__c) ? (__UCLIBC_CTYPE_TOUPPER)[__c] : __c;
275 }
276 # endif
277
278 # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
279 #  define tolower(c)    __tobody(c, tolower, __UCLIBC_CTYPE_TOLOWER, (c))
280 #  define toupper(c)    __tobody(c, toupper, __UCLIBC_CTYPE_TOUPPER, (c))
281 # endif /* Optimizing gcc */
282
283 # if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
284         && defined __UCLIBC_SUSV4_LEGACY__
285 #  define isascii(c)    __isascii (c)
286 #  define toascii(c)    __toascii (c)
287 #  define _tolower(c)   ((int) (__UCLIBC_CTYPE_TOLOWER)[(int) (c)])
288 #  define _toupper(c)   ((int) (__UCLIBC_CTYPE_TOUPPER)[(int) (c)])
289 # endif
290
291 #endif /* not __cplusplus */
292 #endif /* not __NO_CTYPE */
293
294
295 #if defined __USE_GNU && defined __UCLIBC_HAS_XLOCALE__
296 /* The concept of one static locale per category is not very well
297    thought out.  Many applications will need to process its data using
298    information from several different locales.  Another application is
299    the implementation of the internationalization handling in the
300    upcoming ISO C++ standard library.  To support this another set of
301    the functions using locale data exist which have an additional
302    argument.
303
304    Attention: all these functions are *not* standardized in any form.
305    This is a proof-of-concept implementation.  */
306
307 /* Structure for reentrant locale using functions.  This is an
308    (almost) opaque type for the user level programs.  */
309 # include <xlocale.h>
310
311 /* These definitions are similar to the ones above but all functions
312    take as an argument a handle for the locale which shall be used.  */
313 extern int isalnum_l(int, __locale_t) __THROW;
314 libc_hidden_proto(isalnum_l)
315 extern int isalpha_l(int, __locale_t) __THROW;
316 libc_hidden_proto(isalpha_l)
317 extern int iscntrl_l(int, __locale_t) __THROW;
318 libc_hidden_proto(iscntrl_l)
319 extern int isdigit_l(int, __locale_t) __THROW;
320 libc_hidden_proto(isdigit_l)
321 extern int islower_l(int, __locale_t) __THROW;
322 libc_hidden_proto(islower_l)
323 extern int isgraph_l(int, __locale_t) __THROW;
324 libc_hidden_proto(isgraph_l)
325 extern int isprint_l(int, __locale_t) __THROW;
326 libc_hidden_proto(isprint_l)
327 extern int ispunct_l(int, __locale_t) __THROW;
328 libc_hidden_proto(ispunct_l)
329 extern int isspace_l(int, __locale_t) __THROW;
330 libc_hidden_proto(isspace_l)
331 extern int isupper_l(int, __locale_t) __THROW;
332 libc_hidden_proto(isupper_l)
333 extern int isxdigit_l(int, __locale_t) __THROW;
334 libc_hidden_proto(isxdigit_l)
335 extern int isblank_l(int, __locale_t) __THROW;
336 libc_hidden_proto(isblank_l)
337
338 # if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
339         && defined __UCLIBC_SUSV4_LEGACY__
340 /* Return nonzero iff C is in the ASCII set
341    (i.e., is no more than 7 bits wide).  */
342 extern int isascii_l (int __c) __THROW;
343 libc_hidden_proto(isascii_l)
344
345 # endif
346
347 /* Return the lowercase version of C in locale L.  */
348 /* "ordinary" ctype.h has no __tolower, why we try to have it?
349  * remove after 0.9.31
350  *extern int __tolower_l (int __c, __locale_t __l) __THROW; */
351 extern int tolower_l (int __c, __locale_t __l) __THROW;
352 libc_hidden_proto(tolower_l)
353
354 /* Return the uppercase version of C.  */
355 /*extern int __toupper_l (int __c, __locale_t __l) __THROW; */
356 extern int toupper_l (int __c, __locale_t __l) __THROW;
357
358 # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
359 #  define tolower_l(c, locale) __tobody(c, tolower_l, (locale)->__ctype_tolower, (c, locale))
360 #  define toupper_l(c, locale) __tobody(c, toupper_l, (locale)->__ctype_toupper, (c, locale))
361 /*#  define __tolower_l(c, locale) tolower_l((c), (locale)) */
362 /*#  define __toupper_l(c, locale) toupper_l((c), (locale)) */
363 # endif /* Optimizing gcc */
364
365
366 # define __isctype_l(c, type, locale) ((locale)->__ctype_b[(int) (c)] & (__ctype_mask_t) type)
367 # ifndef __NO_CTYPE
368 #  define __isalnum_l(c,l)      __isctype_l((c), _ISalnum, (l))
369 #  define __isalpha_l(c,l)      __isctype_l((c), _ISalpha, (l))
370 #  define __iscntrl_l(c,l)      __isctype_l((c), _IScntrl, (l))
371 #  define __isdigit_l(c,l)      __isctype_l((c), _ISdigit, (l))
372 #  define __islower_l(c,l)      __isctype_l((c), _ISlower, (l))
373 #  define __isgraph_l(c,l)      __isctype_l((c), _ISgraph, (l))
374 #  define __isprint_l(c,l)      __isctype_l((c), _ISprint, (l))
375 #  define __ispunct_l(c,l)      __isctype_l((c), _ISpunct, (l))
376 #  define __isspace_l(c,l)      __isctype_l((c), _ISspace, (l))
377 #  define __isupper_l(c,l)      __isctype_l((c), _ISupper, (l))
378 #  define __isxdigit_l(c,l)     __isctype_l((c), _ISxdigit, (l))
379 #  define __isblank_l(c,l)      __isctype_l((c), _ISblank, (l))
380
381 #  if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
382         && defined __UCLIBC_SUSV4_LEGACY__
383 #   define __isascii_l(c,l)     ((l), __isascii (c))
384 #   define __toascii_l(c,l)     ((l), __toascii (c))
385 #  endif
386
387 #  define isalnum_l(c,l)        __isalnum_l ((c), (l))
388 #  define isalpha_l(c,l)        __isalpha_l ((c), (l))
389 #  define iscntrl_l(c,l)        __iscntrl_l ((c), (l))
390 #  define isdigit_l(c,l)        __isdigit_l ((c), (l))
391 #  define islower_l(c,l)        __islower_l ((c), (l))
392 #  define isgraph_l(c,l)        __isgraph_l ((c), (l))
393 #  define isprint_l(c,l)        __isprint_l ((c), (l))
394 #  define ispunct_l(c,l)        __ispunct_l ((c), (l))
395 #  define isspace_l(c,l)        __isspace_l ((c), (l))
396 #  define isupper_l(c,l)        __isupper_l ((c), (l))
397 #  define isxdigit_l(c,l)       __isxdigit_l ((c), (l))
398 #  define isblank_l(c,l)        __isblank_l ((c), (l))
399
400 #  if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
401         && defined __UCLIBC_SUSV4_LEGACY__
402 #   define isascii_l(c,l)       __isascii_l ((c), (l))
403 #   define toascii_l(c,l)       __toascii_l ((c), (l))
404 #  endif
405
406 # endif /* Not __NO_CTYPE.  */
407
408 #endif /* Use GNU.  */
409
410 __END_DECLS
411
412 #endif /* __UCLIBC_HAS_CTYPE_TABLES__ */
413
414 /* We define {__,}isascii for internal use only */
415 #if defined _LIBC && !defined __UCLIBC_SUSV4_LEGACY__
416 # define __isascii(c) (((c) & ~0x7f) == 0)
417 # define isascii(c) __isascii (c)
418 #endif
419
420 #endif /* ctype.h  */