summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorPaul Janzen <pjanzen@cvs.openbsd.org>2001-06-27 07:17:10 +0000
committerPaul Janzen <pjanzen@cvs.openbsd.org>2001-06-27 07:17:10 +0000
commitf8eaad01d46087ea25b14a0b5ef52c92806347bc (patch)
treeb33441a1cb79c5c2efe25123062059d5a8bdbbe4 /lib/libc/gen
parentb398d24628b1f394267fd1f18e7fa0d865ed4abb (diff)
Make the functions (which get linked in if <ctype.h> isn't #included) behave
correctly. Also, don't let them segfault.
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/isctype.c49
-rw-r--r--lib/libc/gen/tolower_.c8
-rw-r--r--lib/libc/gen/toupper_.c8
3 files changed, 43 insertions, 22 deletions
diff --git a/lib/libc/gen/isctype.c b/lib/libc/gen/isctype.c
index 7745b85e91a..6d66542e3b6 100644
--- a/lib/libc/gen/isctype.c
+++ b/lib/libc/gen/isctype.c
@@ -37,18 +37,21 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: isctype.c,v 1.2 1996/08/19 08:24:38 tholo Exp $";
+static char rcsid[] = "$OpenBSD: isctype.c,v 1.3 2001/06/27 07:17:07 pjanzen Exp $";
#endif /* LIBC_SCCS and not lint */
#define _ANSI_LIBRARY
#include <ctype.h>
+#include <stdio.h>
#undef isalnum
int
isalnum(c)
int c;
{
- return((_ctype_ + 1)[c] & (_U|_L|_N));
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N));
}
#undef isalpha
@@ -56,7 +59,9 @@ int
isalpha(c)
int c;
{
- return((_ctype_ + 1)[c] & (_U|_L));
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & (_U|_L));
}
#undef isblank
@@ -72,7 +77,9 @@ int
iscntrl(c)
int c;
{
- return((_ctype_ + 1)[c] & _C);
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & _C);
}
#undef isdigit
@@ -80,7 +87,9 @@ int
isdigit(c)
int c;
{
- return((_ctype_ + 1)[c] & _N);
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & _N);
}
#undef isgraph
@@ -88,7 +97,9 @@ int
isgraph(c)
int c;
{
- return((_ctype_ + 1)[c] & (_P|_U|_L|_N));
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N));
}
#undef islower
@@ -96,7 +107,9 @@ int
islower(c)
int c;
{
- return((_ctype_ + 1)[c] & _L);
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & _L);
}
#undef isprint
@@ -104,7 +117,9 @@ int
isprint(c)
int c;
{
- return((_ctype_ + 1)[c] & (_P|_U|_L|_N|_B));
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B));
}
#undef ispunct
@@ -112,7 +127,9 @@ int
ispunct(c)
int c;
{
- return((_ctype_ + 1)[c] & _P);
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & _P);
}
#undef isspace
@@ -120,7 +137,9 @@ int
isspace(c)
int c;
{
- return((_ctype_ + 1)[c] & _S);
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & _S);
}
#undef isupper
@@ -128,7 +147,9 @@ int
isupper(c)
int c;
{
- return((_ctype_ + 1)[c] & _U);
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & _U);
}
#undef isxdigit
@@ -136,7 +157,9 @@ int
isxdigit(c)
int c;
{
- return((_ctype_ + 1)[c] & (_N|_X));
+ if (c == EOF)
+ return(0);
+ return((_ctype_ + 1)[(unsigned char)c] & (_N|_X));
}
#undef isascii
@@ -144,6 +167,8 @@ int
isascii(c)
int c;
{
+ if (c == EOF)
+ return(0);
return ((unsigned)(c) <= 0177);
}
diff --git a/lib/libc/gen/tolower_.c b/lib/libc/gen/tolower_.c
index eab1ed3fd73..b145fc46e41 100644
--- a/lib/libc/gen/tolower_.c
+++ b/lib/libc/gen/tolower_.c
@@ -4,16 +4,12 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: tolower_.c,v 1.2 1996/08/19 08:26:52 tholo Exp $";
+static char rcsid[] = "$OpenBSD: tolower_.c,v 1.3 2001/06/27 07:17:08 pjanzen Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <ctype.h>
-#if EOF != -1
-#error "EOF != -1"
-#endif
-
const short _C_tolower_[1 + 256] = {
EOF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -57,5 +53,7 @@ int
tolower(c)
int c;
{
+ if (c != (unsigned char) c)
+ return(c);
return((_tolower_tab_ + 1)[c]);
}
diff --git a/lib/libc/gen/toupper_.c b/lib/libc/gen/toupper_.c
index 4fbfb81b654..b4630483cd0 100644
--- a/lib/libc/gen/toupper_.c
+++ b/lib/libc/gen/toupper_.c
@@ -4,16 +4,12 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: toupper_.c,v 1.2 1996/08/19 08:26:56 tholo Exp $";
+static char rcsid[] = "$OpenBSD: toupper_.c,v 1.3 2001/06/27 07:17:09 pjanzen Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <ctype.h>
-#if EOF != -1
-#error "EOF != -1"
-#endif
-
const short _C_toupper_[1 + 256] = {
EOF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -57,5 +53,7 @@ int
toupper(c)
int c;
{
+ if (c != (unsigned char) c)
+ return(c);
return((_toupper_tab_ + 1)[c]);
}