1 /* $OpenBSD: isctype.c,v 1.11 2005/08/08 08:05:34 espie 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] & (_U|_L|_N))); 45 } 46 47 #undef isalpha 48 int 49 isalpha(int c) 50 { 51 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L))); 52 } 53 54 #undef isblank 55 int 56 isblank(int c) 57 { 58 return (c == ' ' || c == '\t'); 59 } 60 61 #undef iscntrl 62 int 63 iscntrl(int c) 64 { 65 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _C)); 66 } 67 68 #undef isdigit 69 int 70 isdigit(int c) 71 { 72 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N)); 73 } 74 75 #undef isgraph 76 int 77 isgraph(int c) 78 { 79 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N))); 80 } 81 82 #undef islower 83 int 84 islower(int c) 85 { 86 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _L)); 87 } 88 89 #undef isprint 90 int 91 isprint(int c) 92 { 93 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B))); 94 } 95 96 #undef ispunct 97 int 98 ispunct(int c) 99 { 100 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _P)); 101 } 102 103 #undef isspace 104 int 105 isspace(int c) 106 { 107 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S)); 108 } 109 110 #undef isupper 111 int 112 isupper(int c) 113 { 114 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _U)); 115 } 116 117 #undef isxdigit 118 int 119 isxdigit(int c) 120 { 121 return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_N|_X))); 122 } 123 124 #undef isascii 125 int 126 isascii(int c) 127 { 128 return ((unsigned int)c <= 0177); 129 } 130 131 #undef toascii 132 int 133 toascii(int c) 134 { 135 return (c & 0177); 136 } 137 138 #undef _toupper 139 int 140 _toupper(int c) 141 { 142 return (c - 'a' + 'A'); 143 } 144 145 #undef _tolower 146 int 147 _tolower(int c) 148 { 149 return (c - 'A' + 'a'); 150 } 151