1 /* $OpenBSD: isctype.c,v 1.13 2024/02/04 13:03:18 jca 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 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & 45 (_CTYPE_U|_CTYPE_L|_CTYPE_N))); 46 } 47 DEF_STRONG(isalnum); 48 49 #undef isalpha 50 int 51 isalpha(int c) 52 { 53 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & 54 (_CTYPE_U|_CTYPE_L))); 55 } 56 DEF_STRONG(isalpha); 57 58 #undef isblank 59 int 60 isblank(int c) 61 { 62 return (c == ' ' || c == '\t'); 63 } 64 DEF_STRONG(isblank); 65 66 #undef iscntrl 67 int 68 iscntrl(int c) 69 { 70 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_C)); 71 } 72 DEF_STRONG(iscntrl); 73 74 #undef isdigit 75 int 76 isdigit(int c) 77 { 78 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_N)); 79 } 80 DEF_STRONG(isdigit); 81 82 #undef isgraph 83 int 84 isgraph(int c) 85 { 86 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & 87 (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N))); 88 } 89 DEF_STRONG(isgraph); 90 91 #undef islower 92 int 93 islower(int c) 94 { 95 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_L)); 96 } 97 DEF_STRONG(islower); 98 99 #undef isprint 100 int 101 isprint(int c) 102 { 103 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & 104 (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B))); 105 } 106 DEF_STRONG(isprint); 107 108 #undef ispunct 109 int 110 ispunct(int c) 111 { 112 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_P)); 113 } 114 DEF_STRONG(ispunct); 115 116 #undef isspace 117 int 118 isspace(int c) 119 { 120 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_S)); 121 } 122 DEF_STRONG(isspace); 123 124 #undef isupper 125 int 126 isupper(int c) 127 { 128 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_U)); 129 } 130 DEF_STRONG(isupper); 131 132 #undef isxdigit 133 int 134 isxdigit(int c) 135 { 136 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & 137 (_CTYPE_N|_CTYPE_X))); 138 } 139 DEF_STRONG(isxdigit); 140 141 #undef isascii 142 int 143 isascii(int c) 144 { 145 return ((unsigned int)c <= 0177); 146 } 147 DEF_WEAK(isascii); 148 149 #undef toascii 150 int 151 toascii(int c) 152 { 153 return (c & 0177); 154 } 155 156 #undef _toupper 157 int 158 _toupper(int c) 159 { 160 return (c - 'a' + 'A'); 161 } 162 163 #undef _tolower 164 int 165 _tolower(int c) 166 { 167 return (c - 'A' + 'a'); 168 } 169