| 1 | /*	$OpenBSD: ctype.h,v 1.26 2024/02/04 13:03:18 jca 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	_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 |
| 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 | |
| 115 | __only_inline int isalnum(int _c) |
| 116 | { |
| 117 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & |
| 118 | 	 (_CTYPE_U|_CTYPE_L|_CTYPE_N))); |
| 119 | } |
| 120 | |
| 121 | __only_inline int isalpha(int _c) |
| 122 | { |
| 123 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & |
| 124 | 	 (_CTYPE_U|_CTYPE_L))); |
| 125 | } |
| 126 | |
| 127 | __only_inline int iscntrl(int _c) |
| 128 | { |
| 129 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_C)); |
| 130 | } |
| 131 | |
| 132 | __only_inline int isdigit(int _c) |
| 133 | { |
| 134 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_N)); |
| 135 | } |
| 136 | |
| 137 | __only_inline int isgraph(int _c) |
| 138 | { |
| 139 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & |
| 140 | 	 (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N))); |
| 141 | } |
| 142 | |
| 143 | __only_inline int islower(int _c) |
| 144 | { |
| 145 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_L)); |
| 146 | } |
| 147 | |
| 148 | __only_inline int isprint(int _c) |
| 149 | { |
| 150 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & |
| 151 | 	 (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B))); |
| 152 | } |
| 153 | |
| 154 | __only_inline int ispunct(int _c) |
| 155 | { |
| 156 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_P)); |
| 157 | } |
| 158 | |
| 159 | __only_inline int isspace(int _c) |
| 160 | { |
| 161 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_S)); |
| 162 | } |
| 163 | |
| 164 | __only_inline int isupper(int _c) |
| 165 | { |
| 166 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_U)); |
| 167 | } |
| 168 | |
| 169 | __only_inline int isxdigit(int _c) |
| 170 | { |
| 171 | 	return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & |
| 172 | 	 (_CTYPE_N|_CTYPE_X))); |
| 173 | } |
| 174 | |
| 175 | __only_inline int tolower(int _c) |
| 176 | { |
| 177 | 	if ((unsigned int)_c > 255) |
| 178 | 		return (_c); |
| 179 | 	return ((_tolower_tab_ + 1)[_c]); |
| 180 | } |
| 181 | |
| 182 | __only_inline int toupper(int _c) |
| 183 | { |
| 184 | 	if ((unsigned int)_c > 255) |
| 185 | 		return (_c); |
| 186 | 	return ((_toupper_tab_ + 1)[_c]); |
| 187 | } |
| 188 | |
| 189 | #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \ |
| 190 | || __XPG_VISIBLE > 600 |
| 191 | __only_inline int isblank(int _c) |
| 192 | { |
| 193 | 	return (_c == ' ' || _c == '\t'); |
| 194 | } |
| 195 | #endif |
| 196 | |
| 197 | #if __BSD_VISIBLE || __XPG_VISIBLE |
| 198 | __only_inline int isascii(int _c) |
| 199 | { |
| 200 | 	return ((unsigned int)_c <= 0177); |
| 201 | } |
| 202 | |
| 203 | __only_inline int toascii(int _c) |
| 204 | { |
| 205 | 	return (_c & 0177); |
| 206 | } |
| 207 | |
| 208 | __only_inline int _tolower(int _c) |
| 209 | { |
| 210 | 	return (_c - 'A' + 'a'); |
| 211 | } |
| 212 | |
| 213 | __only_inline int _toupper(int _c) |
| 214 | { |
| 215 | 	return (_c - 'a' + 'A'); |
| 216 | } |
| 217 | #endif /* __BSD_VISIBLE || __XPG_VISIBLE */ |
| 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 */ |
| 304 | |
| 305 | #endif /* !_ANSI_LIBRARY */ |
| 306 | |
| 307 | __END_DECLS |
| 308 | |
| 309 | #endif /* !_CTYPE_H_ */ |