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