Annotation of src/include/ctype.h, Revision 1.26
1.26 ! jca 1: /* $OpenBSD: ctype.h,v 1.25 2017/09/05 03:16:13 schwarze Exp $ */
1.1 deraadt 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.
1.13 millert 21: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 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_
1.19 millert 42:
1.1 deraadt 43: #include <sys/cdefs.h>
44:
1.26 ! jca 45: #define _CTYPE_U 0x01
! 46: #define _CTYPE_L 0x02
! 47: #define _CTYPE_N 0x04
! 48: #define _CTYPE_S 0x08
! 49: #define _CTYPE_P 0x10
! 50: #define _CTYPE_C 0x20
! 51: #define _CTYPE_X 0x40
! 52: #define _CTYPE_B 0x80
1.1 deraadt 53:
1.25 schwarze 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:
1.14 millert 61: __BEGIN_DECLS
62:
1.1 deraadt 63: extern const char *_ctype_;
64: extern const short *_tolower_tab_;
65: extern const short *_toupper_tab_;
66:
1.23 guenther 67: #if defined(__GNUC__) || defined(_ANSI_LIBRARY)
1.5 millert 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);
1.1 deraadt 81:
1.19 millert 82: #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
83: || __XPG_VISIBLE > 600
1.5 millert 84: int isblank(int);
1.19 millert 85: #endif
86:
87: #if __BSD_VISIBLE || __XPG_VISIBLE
1.5 millert 88: int isascii(int);
89: int toascii(int);
90: int _tolower(int);
91: int _toupper(int);
1.19 millert 92: #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
1.1 deraadt 93:
1.25 schwarze 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:
1.23 guenther 111: #endif /* __GNUC__ || _ANSI_LIBRARY */
1.15 millert 112:
1.25 schwarze 113: #if !defined(_ANSI_LIBRARY) && !defined(__cplusplus)
1.5 millert 114:
1.24 guenther 115: __only_inline int isalnum(int _c)
1.5 millert 116: {
1.26 ! jca 117: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] &
! 118: (_CTYPE_U|_CTYPE_L|_CTYPE_N)));
1.5 millert 119: }
120:
1.24 guenther 121: __only_inline int isalpha(int _c)
1.5 millert 122: {
1.26 ! jca 123: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] &
! 124: (_CTYPE_U|_CTYPE_L)));
1.5 millert 125: }
126:
1.24 guenther 127: __only_inline int iscntrl(int _c)
1.5 millert 128: {
1.26 ! jca 129: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_C));
1.5 millert 130: }
131:
1.24 guenther 132: __only_inline int isdigit(int _c)
1.5 millert 133: {
1.26 ! jca 134: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_N));
1.5 millert 135: }
136:
1.24 guenther 137: __only_inline int isgraph(int _c)
1.5 millert 138: {
1.26 ! jca 139: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] &
! 140: (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N)));
1.5 millert 141: }
142:
1.24 guenther 143: __only_inline int islower(int _c)
1.5 millert 144: {
1.26 ! jca 145: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_L));
1.5 millert 146: }
147:
1.24 guenther 148: __only_inline int isprint(int _c)
1.5 millert 149: {
1.26 ! jca 150: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] &
! 151: (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B)));
1.5 millert 152: }
153:
1.24 guenther 154: __only_inline int ispunct(int _c)
1.5 millert 155: {
1.26 ! jca 156: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_P));
1.5 millert 157: }
158:
1.24 guenther 159: __only_inline int isspace(int _c)
1.5 millert 160: {
1.26 ! jca 161: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_S));
1.5 millert 162: }
163:
1.24 guenther 164: __only_inline int isupper(int _c)
1.5 millert 165: {
1.26 ! jca 166: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_U));
1.5 millert 167: }
168:
1.24 guenther 169: __only_inline int isxdigit(int _c)
1.5 millert 170: {
1.26 ! jca 171: return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] &
! 172: (_CTYPE_N|_CTYPE_X)));
1.5 millert 173: }
174:
1.24 guenther 175: __only_inline int tolower(int _c)
1.5 millert 176: {
1.24 guenther 177: if ((unsigned int)_c > 255)
178: return (_c);
179: return ((_tolower_tab_ + 1)[_c]);
1.5 millert 180: }
181:
1.24 guenther 182: __only_inline int toupper(int _c)
1.5 millert 183: {
1.24 guenther 184: if ((unsigned int)_c > 255)
185: return (_c);
186: return ((_toupper_tab_ + 1)[_c]);
1.5 millert 187: }
1.1 deraadt 188:
1.19 millert 189: #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
190: || __XPG_VISIBLE > 600
1.24 guenther 191: __only_inline int isblank(int _c)
1.5 millert 192: {
1.24 guenther 193: return (_c == ' ' || _c == '\t');
1.5 millert 194: }
1.19 millert 195: #endif
1.5 millert 196:
1.19 millert 197: #if __BSD_VISIBLE || __XPG_VISIBLE
1.24 guenther 198: __only_inline int isascii(int _c)
1.5 millert 199: {
1.24 guenther 200: return ((unsigned int)_c <= 0177);
1.5 millert 201: }
202:
1.24 guenther 203: __only_inline int toascii(int _c)
1.5 millert 204: {
1.24 guenther 205: return (_c & 0177);
1.5 millert 206: }
207:
1.24 guenther 208: __only_inline int _tolower(int _c)
1.5 millert 209: {
1.24 guenther 210: return (_c - 'A' + 'a');
1.5 millert 211: }
212:
1.24 guenther 213: __only_inline int _toupper(int _c)
1.5 millert 214: {
1.24 guenther 215: return (_c - 'a' + 'A');
1.5 millert 216: }
1.19 millert 217: #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
1.25 schwarze 218:
219: #if __POSIX_VISIBLE >= 200809
220: __only_inline int
221: isalnum_l(int _c, locale_t _l __attribute__((__unused__)))
222: {
223: return isalnum(_c);
224: }
225:
226: __only_inline int
227: isalpha_l(int _c, locale_t _l __attribute__((__unused__)))
228: {
229: return isalpha(_c);
230: }
231:
232: __only_inline int
233: isblank_l(int _c, locale_t _l __attribute__((__unused__)))
234: {
235: return isblank(_c);
236: }
237:
238: __only_inline int
239: iscntrl_l(int _c, locale_t _l __attribute__((__unused__)))
240: {
241: return iscntrl(_c);
242: }
243:
244: __only_inline int
245: isdigit_l(int _c, locale_t _l __attribute__((__unused__)))
246: {
247: return isdigit(_c);
248: }
249:
250: __only_inline int
251: isgraph_l(int _c, locale_t _l __attribute__((__unused__)))
252: {
253: return isgraph(_c);
254: }
255:
256: __only_inline int
257: islower_l(int _c, locale_t _l __attribute__((__unused__)))
258: {
259: return islower(_c);
260: }
261:
262: __only_inline int
263: isprint_l(int _c, locale_t _l __attribute__((__unused__)))
264: {
265: return isprint(_c);
266: }
267:
268: __only_inline int
269: ispunct_l(int _c, locale_t _l __attribute__((__unused__)))
270: {
271: return ispunct(_c);
272: }
273:
274: __only_inline int
275: isspace_l(int _c, locale_t _l __attribute__((__unused__)))
276: {
277: return isspace(_c);
278: }
279:
280: __only_inline int
281: isupper_l(int _c, locale_t _l __attribute__((__unused__)))
282: {
283: return isupper(_c);
284: }
285:
286: __only_inline int
287: isxdigit_l(int _c, locale_t _l __attribute__((__unused__)))
288: {
289: return isxdigit(_c);
290: }
291:
292: __only_inline int
293: tolower_l(int _c, locale_t _l __attribute__((__unused__)))
294: {
295: return tolower(_c);
296: }
297:
298: __only_inline int
299: toupper_l(int _c, locale_t _l __attribute__((__unused__)))
300: {
301: return toupper(_c);
302: }
303: #endif /* __POSIX_VISIBLE >= 200809 */
1.5 millert 304:
1.23 guenther 305: #endif /* !_ANSI_LIBRARY */
1.14 millert 306:
307: __END_DECLS
1.1 deraadt 308:
309: #endif /* !_CTYPE_H_ */