diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-12-11 23:01:41 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-12-11 23:01:41 +0000 |
commit | 3d2d0dd6e38a4a646756782494ce94ec825fd594 (patch) | |
tree | 58f60e118beb047eaba25e424d4e5ea9ead1a606 | |
parent | fc4d67c279b2d8573673469d68082d1f7c280438 (diff) |
Convert ctype.h macros into inline functions. This fixes the issues we
currently have with the macro versions and makes the ctype.h versions
100% identical to what is in libc.
Discussed with pjanzen@ and OK'd by deraadt@.
-rw-r--r-- | include/ctype.h | 181 | ||||
-rw-r--r-- | lib/libc/gen/tolower_.c | 5 | ||||
-rw-r--r-- | lib/libc/gen/toupper_.c | 5 | ||||
-rw-r--r-- | usr.bin/xlint/llib/llib-lposix | 3 | ||||
-rw-r--r-- | usr.bin/xlint/llib/llib-lstdc | 3 |
5 files changed, 152 insertions, 45 deletions
diff --git a/include/ctype.h b/include/ctype.h index 73f3a7d6a67..9a8ff41886d 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ctype.h,v 1.4 2002/02/16 21:27:17 millert Exp $ */ +/* $OpenBSD: ctype.h,v 1.5 2002/12/11 23:01:40 millert Exp $ */ /* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */ /* @@ -54,56 +54,159 @@ #define _X 0x40 #define _B 0x80 +#define EOF (-1) + extern const char *_ctype_; extern const short *_tolower_tab_; extern const short *_toupper_tab_; +#ifdef _ANSI_LIBRARY __BEGIN_DECLS -extern int isalnum(int); -extern int isalpha(int); -extern int iscntrl(int); -extern int isdigit(int); -extern int isgraph(int); -extern int islower(int); -extern int isprint(int); -extern int ispunct(int); -extern int isspace(int); -extern int isupper(int); -extern int isxdigit(int); -extern int tolower(int); -extern int toupper(int); +int isalnum(int); +int isalpha(int); +int iscntrl(int); +int isdigit(int); +int isgraph(int); +int islower(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int isxdigit(int); +int tolower(int); +int toupper(int); #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) -extern int isblank(int); -extern int isascii(int); -extern int toascii(int); -extern int _tolower(int); -extern int _toupper(int); +int isblank(int); +int isascii(int); +int toascii(int); +int _tolower(int); +int _toupper(int); #endif __END_DECLS -#define isdigit(c) ((_ctype_ + 1)[(unsigned char)(c)] & _N) -#define islower(c) ((_ctype_ + 1)[(unsigned char)(c)] & _L) -#define isspace(c) ((_ctype_ + 1)[(unsigned char)(c)] & _S) -#define ispunct(c) ((_ctype_ + 1)[(unsigned char)(c)] & _P) -#define isupper(c) ((_ctype_ + 1)[(unsigned char)(c)] & _U) -#define isalpha(c) ((_ctype_ + 1)[(unsigned char)(c)] & (_U|_L)) -#define isxdigit(c) ((_ctype_ + 1)[(unsigned char)(c)] & (_N|_X)) -#define isalnum(c) ((_ctype_ + 1)[(unsigned char)(c)] & (_U|_L|_N)) -#define isprint(c) ((_ctype_ + 1)[(unsigned char)(c)] & (_P|_U|_L|_N|_B)) -#define isgraph(c) ((_ctype_ + 1)[(unsigned char)(c)] & (_P|_U|_L|_N)) -#define iscntrl(c) ((_ctype_ + 1)[(unsigned char)(c)] & _C) -#define tolower(c) ((_tolower_tab_ + 1)[(unsigned char)(c)]) -#define toupper(c) ((_toupper_tab_ + 1)[(unsigned char)(c)]) +#else /* !_ANSI_LIBRARY */ + +static __inline int isalnum(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N)); +} + +static __inline int isalpha(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & (_U|_L)); +} + +static __inline int iscntrl(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & _C); +} + +static __inline int isdigit(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & _N); +} + +static __inline int isgraph(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N)); +} + +static __inline int islower(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & _L); +} + +static __inline int isprint(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B)); +} + +static __inline int ispunct(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & _P); +} + +static __inline int isspace(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & _S); +} + +static __inline int isupper(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & _U); +} + +static __inline int isxdigit(int c) +{ + if (c == EOF) + return (0); + return ((_ctype_ + 1)[(unsigned char)c] & (_N|_X)); +} + +static __inline int tolower(int c) +{ + if (c != (unsigned char) c) + return (c); + return ((_tolower_tab_ + 1)[c]); +} + +static __inline int toupper(int c) +{ + if (c != (unsigned char) c) + return (c); + return ((_toupper_tab_ + 1)[c]); +} #if !defined(_ANSI_SOURCE) && !defined (_POSIX_SOURCE) -#if notyet -#define isblank(c) ((_ctype_ + 1)[(unsigned char)(c)] & _B) -#endif -#define isascii(c) ((unsigned char)(c) <= 0177) -#define toascii(c) ((c) & 0177) -#define _tolower(c) ((c) - 'A' + 'a') -#define _toupper(c) ((c) - 'a' + 'A') +static __inline int isblank(int c) +{ + return (c == ' ' || c == '\t'); +} + +static __inline int isascii(int c) +{ + if (c == EOF) + return (0); + return ((unsigned)(c) <= 0177); +} + +static __inline int toascii(int c) +{ + return (c & 0177); +} + +static __inline int _tolower(int c) +{ + return (c - 'A' + 'a'); +} + +static __inline int _toupper(int c) +{ + return (c - 'a' + 'A'); +} #endif +#endif /* !_ANSI_LIBRARY */ + #endif /* !_CTYPE_H_ */ diff --git a/lib/libc/gen/tolower_.c b/lib/libc/gen/tolower_.c index b145fc46e41..d0d78865fe5 100644 --- a/lib/libc/gen/tolower_.c +++ b/lib/libc/gen/tolower_.c @@ -4,11 +4,12 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: tolower_.c,v 1.3 2001/06/27 07:17:08 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: tolower_.c,v 1.4 2002/12/11 23:01:40 millert Exp $"; #endif /* LIBC_SCCS and not lint */ -#include <stdio.h> +#define _ANSI_LIBRARY #include <ctype.h> +#include <stdio.h> const short _C_tolower_[1 + 256] = { EOF, diff --git a/lib/libc/gen/toupper_.c b/lib/libc/gen/toupper_.c index b4630483cd0..b6ab3090006 100644 --- a/lib/libc/gen/toupper_.c +++ b/lib/libc/gen/toupper_.c @@ -4,11 +4,12 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: toupper_.c,v 1.3 2001/06/27 07:17:09 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: toupper_.c,v 1.4 2002/12/11 23:01:40 millert Exp $"; #endif /* LIBC_SCCS and not lint */ -#include <stdio.h> +#define _ANSI_LIBRARY #include <ctype.h> +#include <stdio.h> const short _C_toupper_[1 + 256] = { EOF, diff --git a/usr.bin/xlint/llib/llib-lposix b/usr.bin/xlint/llib/llib-lposix index 99645c659eb..5461423444f 100644 --- a/usr.bin/xlint/llib/llib-lposix +++ b/usr.bin/xlint/llib/llib-lposix @@ -1,4 +1,4 @@ -/* $OpenBSD: llib-lposix,v 1.2 1996/06/26 05:44:28 deraadt Exp $ */ +/* $OpenBSD: llib-lposix,v 1.3 2002/12/11 23:01:40 millert Exp $ */ /* $NetBSD: llib-lposix,v 1.2 1995/07/03 21:25:09 cgd Exp $ */ /* @@ -35,6 +35,7 @@ /* LINTLIBRARY */ #define _POSIX_SOURCE +#define _ANSI_LIBRARY #include <sys/types.h> #include <sys/stat.h> diff --git a/usr.bin/xlint/llib/llib-lstdc b/usr.bin/xlint/llib/llib-lstdc index b75589b72d5..c1f19e8daeb 100644 --- a/usr.bin/xlint/llib/llib-lstdc +++ b/usr.bin/xlint/llib/llib-lstdc @@ -1,4 +1,4 @@ -/* $OpenBSD: llib-lstdc,v 1.3 1997/02/17 08:58:50 deraadt Exp $ */ +/* $OpenBSD: llib-lstdc,v 1.4 2002/12/11 23:01:40 millert Exp $ */ /* $NetBSD: llib-lstdc,v 1.3 1995/07/03 21:39:28 cgd Exp $ */ /* @@ -35,6 +35,7 @@ /* LINTLIBRARY */ #define _ANSI_SOURCE +#define _ANSI_LIBRARY #include <assert.h> #include <ctype.h> |