1 #ifndef _CTYPE_H_
2 #define _CTYPE_H_
3
4 #include "_ansi.h"
5 #include <sys/cdefs.h>
6
7 #if __POSIX_VISIBLE >= 200809 || __MISC_VISIBLE || defined (_COMPILING_NEWLIB)
8 #include <sys/_locale.h>
9 #endif
10
11 _BEGIN_STD_C
12
13 int isalnum (int __c);
14 int isalpha (int __c);
15 int iscntrl (int __c);
16 int isdigit (int __c);
17 int isgraph (int __c);
18 int islower (int __c);
19 int isprint (int __c);
20 int ispunct (int __c);
21 int isspace (int __c);
22 int isupper (int __c);
23 int isxdigit (int __c);
24 int tolower (int __c);
25 int toupper (int __c);
26
27 #if __ISO_C_VISIBLE >= 1999
28 int isblank (int __c);
29 #endif
30
31 #if __MISC_VISIBLE || __XSI_VISIBLE
32 int isascii (int __c);
33 int toascii (int __c);
34 #define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
35 #define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A')
36 #endif
37
38 #if __POSIX_VISIBLE >= 200809
39 extern int isalnum_l (int __c, locale_t __l);
40 extern int isalpha_l (int __c, locale_t __l);
41 extern int isblank_l (int __c, locale_t __l);
42 extern int iscntrl_l (int __c, locale_t __l);
43 extern int isdigit_l (int __c, locale_t __l);
44 extern int isgraph_l (int __c, locale_t __l);
45 extern int islower_l (int __c, locale_t __l);
46 extern int isprint_l (int __c, locale_t __l);
47 extern int ispunct_l (int __c, locale_t __l);
48 extern int isspace_l (int __c, locale_t __l);
49 extern int isupper_l (int __c, locale_t __l);
50 extern int isxdigit_l(int __c, locale_t __l);
51 extern int tolower_l (int __c, locale_t __l);
52 extern int toupper_l (int __c, locale_t __l);
53 #endif
54
55 #if __MISC_VISIBLE
56 extern int isascii_l (int __c, locale_t __l);
57 extern int toascii_l (int __c, locale_t __l);
58 #endif
59
60 #define _U 01
61 #define _L 02
62 #define _N 04
63 #define _S 010
64 #define _P 020
65 #define _C 040
66 #define _X 0100
67 #define _B 0200
68
69 /* For C++ backward-compatibility only. */
70 extern __IMPORT const char _ctype_[];
71
72 #ifdef __HAVE_LOCALE_INFO__
73 const char *__locale_ctype_ptr (void);
74 #else
75 #define __locale_ctype_ptr() _ctype_
76 #endif
77
78 # define __CTYPE_PTR (__locale_ctype_ptr ())
79
80 #ifndef __cplusplus
81 /* These macros are intentionally written in a manner that will trigger
82 a gcc -Wall warning if the user mistakenly passes a 'char' instead
83 of an int containing an 'unsigned char'. Note that the sizeof will
84 always be 1, which is what we want for mapping EOF to __CTYPE_PTR[0];
85 the use of a raw index inside the sizeof triggers the gcc warning if
86 __c was of type char, and sizeof masks side effects of the extra __c.
87 Meanwhile, the real index to __CTYPE_PTR+1 must be cast to int,
88 since isalpha(0x100000001LL) must equal isalpha(1), rather than being
89 an out-of-bounds reference on a 64-bit machine. */
90 #pragma GCC diagnostic push
91 #pragma GCC diagnostic ignored "-Wchar-subscripts"
__ctype_lookup(char c)92 static inline char __ctype_lookup(char c) {
93 return ((__CTYPE_PTR+sizeof(""[c]))[(int)(c)]);
94 }
95 #pragma GCC diagnostic pop
96
97 #define isalpha(__c) (__ctype_lookup(__c)&(_U|_L))
98 #define isupper(__c) ((__ctype_lookup(__c)&(_U|_L))==_U)
99 #define islower(__c) ((__ctype_lookup(__c)&(_U|_L))==_L)
100 #define isdigit(__c) (__ctype_lookup(__c)&_N)
101 #define isxdigit(__c) (__ctype_lookup(__c)&(_X|_N))
102 #define isspace(__c) (__ctype_lookup(__c)&_S)
103 #define ispunct(__c) (__ctype_lookup(__c)&_P)
104 #define isalnum(__c) (__ctype_lookup(__c)&(_U|_L|_N))
105 #define isprint(__c) (__ctype_lookup(__c)&(_P|_U|_L|_N|_B))
106 #define isgraph(__c) (__ctype_lookup(__c)&(_P|_U|_L|_N))
107 #define iscntrl(__c) (__ctype_lookup(__c)&_C)
108
109 #if defined(__GNUC__) && __ISO_C_VISIBLE >= 1999
110 #define isblank(__c) \
111 __extension__ ({ __typeof__ (__c) __x = (__c); \
112 (__ctype_lookup(__x)&_B) || (int) (__x) == '\t';})
113 #endif
114
115 #if __POSIX_VISIBLE >= 200809
116 #ifdef __HAVE_LOCALE_INFO__
117 const char *__locale_ctype_ptr_l (locale_t);
118 #else
119 #define __locale_ctype_ptr_l(l) _ctype_
120 #endif
121
122 #pragma GCC diagnostic push
123 #pragma GCC diagnostic ignored "-Wchar-subscripts"
__ctype_lookup_l(char c,locale_t l)124 static inline char __ctype_lookup_l(char c, locale_t l) {
125 return ((__locale_ctype_ptr_l(l)+sizeof(""[c]))[(int)(c)]);
126 }
127 #pragma GCC diagnostic pop
128
129 #define isalpha_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_U|_L))
130 #define isupper_l(__c,__l) ((__ctype_lookup_l(__c,__l)&(_U|_L))==_U)
131 #define islower_l(__c,__l) ((__ctype_lookup_l(__c,__l)&(_U|_L))==_L)
132 #define isdigit_l(__c,__l) (__ctype_lookup_l(__c,__l)&_N)
133 #define isxdigit_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_X|_N))
134 #define isspace_l(__c,__l) (__ctype_lookup_l(__c,__l)&_S)
135 #define ispunct_l(__c,__l) (__ctype_lookup_l(__c,__l)&_P)
136 #define isalnum_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_U|_L|_N))
137 #define isprint_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_P|_U|_L|_N|_B))
138 #define isgraph_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_P|_U|_L|_N))
139 #define iscntrl_l(__c,__l) (__ctype_lookup_l(__c,__l)&_C)
140
141 #if defined(__GNUC__)
142 #define isblank_l(__c, __l) \
143 __extension__ ({ __typeof__ (__c) __x = (__c); \
144 (__ctype_lookup_l(__x,__l)&_B) || (int) (__x) == '\t';})
145 #endif
146
147 #endif /* __POSIX_VISIBLE >= 200809 */
148
149 #if __MISC_VISIBLE || __XSI_VISIBLE
150 #define isascii(__c) ((unsigned)(__c)<=0177)
151 #define toascii(__c) ((__c)&0177)
152 #endif
153
154 #if __MISC_VISIBLE
155 #define isascii_l(__c,__l) ((__l),(unsigned)(__c)<=0177)
156 #define toascii_l(__c,__l) ((__l),(__c)&0177)
157 #endif
158
159 /* Non-gcc versions will get the library versions, and will be
160 slightly slower. These macros are not NLS-aware so they are
161 disabled if the system supports the extended character sets. */
162 # if defined(__GNUC__)
163 # if !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
164 # define toupper(__c) \
165 __extension__ ({ __typeof__ (__c) __x = (__c); \
166 islower (__x) ? (int) __x - 'a' + 'A' : (int) __x;})
167 # define tolower(__c) \
168 __extension__ ({ __typeof__ (__c) __x = (__c); \
169 isupper (__x) ? (int) __x - 'A' + 'a' : (int) __x;})
170 # else /* _MB_EXTENDED_CHARSETS* */
171 /* Allow a gcc warning if the user passed 'char', but defer to the
172 function. */
173 # define toupper(__c) \
174 __extension__ ({ __typeof__ (__c) __x = (__c); \
175 (void) __CTYPE_PTR[__x]; (toupper) (__x);})
176 # define tolower(__c) \
177 __extension__ ({ __typeof__ (__c) __x = (__c); \
178 (void) __CTYPE_PTR[__x]; (tolower) (__x);})
179 # endif /* _MB_EXTENDED_CHARSETS* */
180 # endif /* __GNUC__ */
181
182 #if __POSIX_VISIBLE >= 200809
183 #endif /* __POSIX_VISIBLE >= 200809 */
184
185 #endif /* !__cplusplus */
186
187 _END_STD_C
188
189 #endif /* _CTYPE_H_ */
190