1 /* $OpenBSD: ctype.h,v 1.25 2017/09/05 03:16:13 schwarze Exp $ */
2 /* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */
3
4 /*
5 * Copyright (c) 1989 The Regents of the University of California.
6 * All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed
9 * to the University of California by American Telephone and Telegraph
10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 * the permission of UNIX System Laboratories, Inc.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * @(#)ctype.h 5.3 (Berkeley) 4/3/91
38 */
39
40 #ifndef _CTYPE_H_
41 #define _CTYPE_H_
42
43 #include <sys/cdefs.h>
44
45 #define _U 0x01
46 #define _L 0x02
47 #define _N 0x04
48 #define _S 0x08
49 #define _P 0x10
50 #define _C 0x20
51 #define _X 0x40
52 #define _B 0x80
53
54 #if __POSIX_VISIBLE >= 200809
55 #ifndef _LOCALE_T_DEFINED_
56 #define _LOCALE_T_DEFINED_
57 typedef void *locale_t;
58 #endif
59 #endif
60
61 __BEGIN_DECLS
62
63 extern const char *_ctype_;
64 extern const short *_tolower_tab_;
65 extern const short *_toupper_tab_;
66
67 #if defined(__GNUC__) || defined(_ANSI_LIBRARY)
68 int isalnum(int);
69 int isalpha(int);
70 int iscntrl(int);
71 int isdigit(int);
72 int isgraph(int);
73 int islower(int);
74 int isprint(int);
75 int ispunct(int);
76 int isspace(int);
77 int isupper(int);
78 int isxdigit(int);
79 int tolower(int);
80 int toupper(int);
81
82 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
83 || __XPG_VISIBLE > 600
84 int isblank(int);
85 #endif
86
87 #if __BSD_VISIBLE || __XPG_VISIBLE
88 int isascii(int);
89 int toascii(int);
90 int _tolower(int);
91 int _toupper(int);
92 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
93
94 #if __POSIX_VISIBLE >= 200809
95 int isalnum_l(int, locale_t);
96 int isalpha_l(int, locale_t);
97 int isblank_l(int, locale_t);
98 int iscntrl_l(int, locale_t);
99 int isdigit_l(int, locale_t);
100 int isgraph_l(int, locale_t);
101 int islower_l(int, locale_t);
102 int isprint_l(int, locale_t);
103 int ispunct_l(int, locale_t);
104 int isspace_l(int, locale_t);
105 int isupper_l(int, locale_t);
106 int isxdigit_l(int, locale_t);
107 int tolower_l(int, locale_t);
108 int toupper_l(int, locale_t);
109 #endif
110
111 #endif /* __GNUC__ || _ANSI_LIBRARY */
112
113 #if !defined(_ANSI_LIBRARY) && !defined(__cplusplus)
114
isalnum(int _c)115 __only_inline int isalnum(int _c)
116 {
117 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_U|_L|_N)));
118 }
119
isalpha(int _c)120 __only_inline int isalpha(int _c)
121 {
122 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_U|_L)));
123 }
124
iscntrl(int _c)125 __only_inline int iscntrl(int _c)
126 {
127 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _C));
128 }
129
isdigit(int _c)130 __only_inline int isdigit(int _c)
131 {
132 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _N));
133 }
134
isgraph(int _c)135 __only_inline int isgraph(int _c)
136 {
137 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_P|_U|_L|_N)));
138 }
139
islower(int _c)140 __only_inline int islower(int _c)
141 {
142 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _L));
143 }
144
isprint(int _c)145 __only_inline int isprint(int _c)
146 {
147 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_P|_U|_L|_N|_B)));
148 }
149
ispunct(int _c)150 __only_inline int ispunct(int _c)
151 {
152 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _P));
153 }
154
isspace(int _c)155 __only_inline int isspace(int _c)
156 {
157 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _S));
158 }
159
isupper(int _c)160 __only_inline int isupper(int _c)
161 {
162 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _U));
163 }
164
isxdigit(int _c)165 __only_inline int isxdigit(int _c)
166 {
167 return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_N|_X)));
168 }
169
tolower(int _c)170 __only_inline int tolower(int _c)
171 {
172 if ((unsigned int)_c > 255)
173 return (_c);
174 return ((_tolower_tab_ + 1)[_c]);
175 }
176
toupper(int _c)177 __only_inline int toupper(int _c)
178 {
179 if ((unsigned int)_c > 255)
180 return (_c);
181 return ((_toupper_tab_ + 1)[_c]);
182 }
183
184 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
185 || __XPG_VISIBLE > 600
isblank(int _c)186 __only_inline int isblank(int _c)
187 {
188 return (_c == ' ' || _c == '\t');
189 }
190 #endif
191
192 #if __BSD_VISIBLE || __XPG_VISIBLE
isascii(int _c)193 __only_inline int isascii(int _c)
194 {
195 return ((unsigned int)_c <= 0177);
196 }
197
toascii(int _c)198 __only_inline int toascii(int _c)
199 {
200 return (_c & 0177);
201 }
202
_tolower(int _c)203 __only_inline int _tolower(int _c)
204 {
205 return (_c - 'A' + 'a');
206 }
207
_toupper(int _c)208 __only_inline int _toupper(int _c)
209 {
210 return (_c - 'a' + 'A');
211 }
212 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
213
214 #if __POSIX_VISIBLE >= 200809
215 __only_inline int
isalnum_l(int _c,locale_t _l)216 isalnum_l(int _c, locale_t _l __attribute__((__unused__)))
217 {
218 return isalnum(_c);
219 }
220
221 __only_inline int
isalpha_l(int _c,locale_t _l)222 isalpha_l(int _c, locale_t _l __attribute__((__unused__)))
223 {
224 return isalpha(_c);
225 }
226
227 __only_inline int
isblank_l(int _c,locale_t _l)228 isblank_l(int _c, locale_t _l __attribute__((__unused__)))
229 {
230 return isblank(_c);
231 }
232
233 __only_inline int
iscntrl_l(int _c,locale_t _l)234 iscntrl_l(int _c, locale_t _l __attribute__((__unused__)))
235 {
236 return iscntrl(_c);
237 }
238
239 __only_inline int
isdigit_l(int _c,locale_t _l)240 isdigit_l(int _c, locale_t _l __attribute__((__unused__)))
241 {
242 return isdigit(_c);
243 }
244
245 __only_inline int
isgraph_l(int _c,locale_t _l)246 isgraph_l(int _c, locale_t _l __attribute__((__unused__)))
247 {
248 return isgraph(_c);
249 }
250
251 __only_inline int
islower_l(int _c,locale_t _l)252 islower_l(int _c, locale_t _l __attribute__((__unused__)))
253 {
254 return islower(_c);
255 }
256
257 __only_inline int
isprint_l(int _c,locale_t _l)258 isprint_l(int _c, locale_t _l __attribute__((__unused__)))
259 {
260 return isprint(_c);
261 }
262
263 __only_inline int
ispunct_l(int _c,locale_t _l)264 ispunct_l(int _c, locale_t _l __attribute__((__unused__)))
265 {
266 return ispunct(_c);
267 }
268
269 __only_inline int
isspace_l(int _c,locale_t _l)270 isspace_l(int _c, locale_t _l __attribute__((__unused__)))
271 {
272 return isspace(_c);
273 }
274
275 __only_inline int
isupper_l(int _c,locale_t _l)276 isupper_l(int _c, locale_t _l __attribute__((__unused__)))
277 {
278 return isupper(_c);
279 }
280
281 __only_inline int
isxdigit_l(int _c,locale_t _l)282 isxdigit_l(int _c, locale_t _l __attribute__((__unused__)))
283 {
284 return isxdigit(_c);
285 }
286
287 __only_inline int
tolower_l(int _c,locale_t _l)288 tolower_l(int _c, locale_t _l __attribute__((__unused__)))
289 {
290 return tolower(_c);
291 }
292
293 __only_inline int
toupper_l(int _c,locale_t _l)294 toupper_l(int _c, locale_t _l __attribute__((__unused__)))
295 {
296 return toupper(_c);
297 }
298 #endif /* __POSIX_VISIBLE >= 200809 */
299
300 #endif /* !_ANSI_LIBRARY */
301
302 __END_DECLS
303
304 #endif /* !_CTYPE_H_ */
305