From e560c275cd7b74e5dd2a7bf954a4ce1a326436a8 Mon Sep 17 00:00:00 2001 From: hselasky Date: Fri, 5 Apr 2019 11:37:17 +0000 Subject: [PATCH] MFC r345499: Change all kernel C-type macros into static inline functions. The current kernel C-type macros might obscurely hide the fact that the input argument might be used multiple times. This breaks code like: isalpha(*ptr++) Use static inline functions instead of macros to fix this. Reviewed by: kib @ Differential Revision: https://reviews.freebsd.org/D19694 Sponsored by: Mellanox Technologies git-svn-id: svn://svn.freebsd.org/base/stable/9@345944 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/sys/ctype.h | 72 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/sys/sys/ctype.h b/sys/sys/ctype.h index 5022d40c1..55d8b801a 100644 --- a/sys/sys/ctype.h +++ b/sys/sys/ctype.h @@ -39,19 +39,65 @@ #ifdef _KERNEL -#define isspace(c) ((c) == ' ' || ((c) >= '\t' && (c) <= '\r')) -#define isascii(c) (((c) & ~0x7f) == 0) -#define isupper(c) ((c) >= 'A' && (c) <= 'Z') -#define islower(c) ((c) >= 'a' && (c) <= 'z') -#define isalpha(c) (isupper(c) || islower(c)) -#define isdigit(c) ((c) >= '0' && (c) <= '9') -#define isxdigit(c) (isdigit(c) \ - || ((c) >= 'A' && (c) <= 'F') \ - || ((c) >= 'a' && (c) <= 'f')) -#define isprint(c) ((c) >= ' ' && (c) <= '~') - -#define toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z'))) -#define tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z'))) +static __inline int +isspace(int c) +{ + return (c == ' ' || (c >= '\t' && c <= '\r')); +} + +static __inline int +isascii(int c) +{ + return ((c & ~0x7f) == 0); +} + +static __inline int +isupper(int c) +{ + return (c >= 'A' && c <= 'Z'); +} + +static __inline int +islower(int c) +{ + return (c >= 'a' && c <= 'z'); +} + +static __inline int +isalpha(int c) +{ + return (isupper(c) || islower(c)); +} + +static __inline int +isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} + +static __inline int +isxdigit(int c) +{ + return (isdigit(c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); +} + +static __inline int +isprint(int c) +{ + return (c >= ' ' && c <= '~'); +} + +static __inline int +toupper(int c) +{ + return (c - 0x20 * ((c >= 'a') && (c <= 'z'))); +} + +static __inline int +tolower(int c) +{ + return (c + 0x20 * ((c >= 'A') && (c <= 'Z'))); +} #endif #endif /* !_SYS_CTYPE_H_ */ -- 2.42.0