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_
57typedef void	*locale_t;
58#endif
59#endif
60
61__BEGIN_DECLS
62
63extern const char	*_ctype_;
64extern const short	*_tolower_tab_;
65extern const short	*_toupper_tab_;
66
67#if defined(__GNUC__) || defined(_ANSI_LIBRARY)
68int	isalnum(int);
69int	isalpha(int);
70int	iscntrl(int);
71int	isdigit(int);
72int	isgraph(int);
73int	islower(int);
74int	isprint(int);
75int	ispunct(int);
76int	isspace(int);
77int	isupper(int);
78int	isxdigit(int);
79int	tolower(int);
80int	toupper(int);
81
82#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
83    || __XPG_VISIBLE > 600
84int	isblank(int);
85#endif
86
87#if __BSD_VISIBLE || __XPG_VISIBLE
88int	isascii(int);
89int	toascii(int);
90int	_tolower(int);
91int	_toupper(int);
92#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
93
94#if __POSIX_VISIBLE >= 200809
95int	isalnum_l(int, locale_t);
96int	isalpha_l(int, locale_t);
97int	isblank_l(int, locale_t);
98int	iscntrl_l(int, locale_t);
99int	isdigit_l(int, locale_t);
100int	isgraph_l(int, locale_t);
101int	islower_l(int, locale_t);
102int	isprint_l(int, locale_t);
103int	ispunct_l(int, locale_t);
104int	isspace_l(int, locale_t);
105int	isupper_l(int, locale_t);
106int	isxdigit_l(int, locale_t);
107int	tolower_l(int, locale_t);
108int	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
221isalnum_l(int _c, locale_t _l __attribute__((__unused__)))
222{
223	return isalnum(_c);
224}
225
226__only_inline int
227isalpha_l(int _c, locale_t _l __attribute__((__unused__)))
228{
229	return isalpha(_c);
230}
231
232__only_inline int
233isblank_l(int _c, locale_t _l __attribute__((__unused__)))
234{
235	return isblank(_c);
236}
237
238__only_inline int
239iscntrl_l(int _c, locale_t _l __attribute__((__unused__)))
240{
241	return iscntrl(_c);
242}
243
244__only_inline int
245isdigit_l(int _c, locale_t _l __attribute__((__unused__)))
246{
247	return isdigit(_c);
248}
249
250__only_inline int
251isgraph_l(int _c, locale_t _l __attribute__((__unused__)))
252{
253	return isgraph(_c);
254}
255
256__only_inline int
257islower_l(int _c, locale_t _l __attribute__((__unused__)))
258{
259	return islower(_c);
260}
261
262__only_inline int
263isprint_l(int _c, locale_t _l __attribute__((__unused__)))
264{
265	return isprint(_c);
266}
267
268__only_inline int
269ispunct_l(int _c, locale_t _l __attribute__((__unused__)))
270{
271	return ispunct(_c);
272}
273
274__only_inline int
275isspace_l(int _c, locale_t _l __attribute__((__unused__)))
276{
277	return isspace(_c);
278}
279
280__only_inline int
281isupper_l(int _c, locale_t _l __attribute__((__unused__)))
282{
283	return isupper(_c);
284}
285
286__only_inline int
287isxdigit_l(int _c, locale_t _l __attribute__((__unused__)))
288{
289	return isxdigit(_c);
290}
291
292__only_inline int
293tolower_l(int _c, locale_t _l __attribute__((__unused__)))
294{
295	return tolower(_c);
296}
297
298__only_inline int
299toupper_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_ */
310