xref: /openbsd-src/lib/libc/gen/isctype.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  */
38 
39 #if defined(LIBC_SCCS) && !defined(lint)
40 static char rcsid[] = "$OpenBSD: isctype.c,v 1.3 2001/06/27 07:17:07 pjanzen Exp $";
41 #endif /* LIBC_SCCS and not lint */
42 
43 #define _ANSI_LIBRARY
44 #include <ctype.h>
45 #include <stdio.h>
46 
47 #undef isalnum
48 int
49 isalnum(c)
50 	int c;
51 {
52 	if (c == EOF)
53 		return(0);
54 	return((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N));
55 }
56 
57 #undef isalpha
58 int
59 isalpha(c)
60 	int c;
61 {
62 	if (c == EOF)
63 		return(0);
64 	return((_ctype_ + 1)[(unsigned char)c] & (_U|_L));
65 }
66 
67 #undef isblank
68 int
69 isblank(c)
70 	int c;
71 {
72 	return(c == ' ' || c == '\t');
73 }
74 
75 #undef iscntrl
76 int
77 iscntrl(c)
78 	int c;
79 {
80 	if (c == EOF)
81 		return(0);
82 	return((_ctype_ + 1)[(unsigned char)c] & _C);
83 }
84 
85 #undef isdigit
86 int
87 isdigit(c)
88 	int c;
89 {
90 	if (c == EOF)
91 		return(0);
92 	return((_ctype_ + 1)[(unsigned char)c] & _N);
93 }
94 
95 #undef isgraph
96 int
97 isgraph(c)
98 	int c;
99 {
100 	if (c == EOF)
101 		return(0);
102 	return((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N));
103 }
104 
105 #undef islower
106 int
107 islower(c)
108 	int c;
109 {
110 	if (c == EOF)
111 		return(0);
112 	return((_ctype_ + 1)[(unsigned char)c] & _L);
113 }
114 
115 #undef isprint
116 int
117 isprint(c)
118 	int c;
119 {
120 	if (c == EOF)
121 		return(0);
122 	return((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B));
123 }
124 
125 #undef ispunct
126 int
127 ispunct(c)
128 	int c;
129 {
130 	if (c == EOF)
131 		return(0);
132 	return((_ctype_ + 1)[(unsigned char)c] & _P);
133 }
134 
135 #undef isspace
136 int
137 isspace(c)
138 	int c;
139 {
140 	if (c == EOF)
141 		return(0);
142 	return((_ctype_ + 1)[(unsigned char)c] & _S);
143 }
144 
145 #undef isupper
146 int
147 isupper(c)
148 	int c;
149 {
150 	if (c == EOF)
151 		return(0);
152 	return((_ctype_ + 1)[(unsigned char)c] & _U);
153 }
154 
155 #undef isxdigit
156 int
157 isxdigit(c)
158 	int c;
159 {
160 	if (c == EOF)
161 		return(0);
162 	return((_ctype_ + 1)[(unsigned char)c] & (_N|_X));
163 }
164 
165 #undef isascii
166 int
167 isascii(c)
168 	int c;
169 {
170 	if (c == EOF)
171 		return(0);
172 	return ((unsigned)(c) <= 0177);
173 }
174 
175 #undef toascii
176 int
177 toascii(c)
178 	int c;
179 {
180 	return ((c) & 0177);
181 }
182 
183 #undef _toupper
184 int
185 _toupper(c)
186 	int c;
187 {
188 	return (c - 'a' + 'A');
189 }
190 
191 #undef _tolower
192 int
193 _tolower(c)
194 	int c;
195 {
196 	return (c - 'A' + 'a');
197 }
198