From 1ec59f28cea56f1afced0994127e2df62300e618 Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 9 Sep 2020 08:47:26 +0100 Subject: [PATCH] LibC: Make isalum/isalpha/etc. functions instead of macros These are supposed to be both functions and macros. I'm not sure how to provide the functions at the same time as the macros, as they collide with each other and cause compile errors. However, some ports fully expect them to be functions. For example, OpenSSH stores them into structures as function pointers. --- Libraries/LibC/ctype.h | 76 ++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/Libraries/LibC/ctype.h b/Libraries/LibC/ctype.h index 49e6a26954..f6a4d4be90 100644 --- a/Libraries/LibC/ctype.h +++ b/Libraries/LibC/ctype.h @@ -45,29 +45,61 @@ extern const char _ctype_[256]; int tolower(int); int toupper(int); -int isalnum(int); -int isalpha(int); -int iscntrl(int); -int isdigit(int); -int isxdigit(int); -int isspace(int); -int ispunct(int); -int isprint(int); -int isgraph(int); -int islower(int); -int isupper(int); -#define isalnum(c) (_ctype_[(unsigned char)(c)] & (_U | _L | _N)) -#define isalpha(c) (_ctype_[(unsigned char)(c)] & (_U | _L)) -#define iscntrl(c) (_ctype_[(unsigned char)(c)] & (_C)) -#define isdigit(c) (_ctype_[(unsigned char)(c)] & (_N)) -#define isxdigit(c) (_ctype_[(unsigned char)(c)] & (_N | _X)) -#define isspace(c) (_ctype_[(unsigned char)(c)] & (_S)) -#define ispunct(c) (_ctype_[(unsigned char)(c)] & (_P)) -#define isprint(c) (_ctype_[(unsigned char)(c)] & (_P | _U | _L | _N | _B)) -#define isgraph(c) (_ctype_[(unsigned char)(c)] & (_P | _U | _L | _N)) -#define islower(c) ((_ctype_[(unsigned char)(c)] & (_U | _L)) == _L) -#define isupper(c) ((_ctype_[(unsigned char)(c)] & (_U | _L)) == _U) +static inline int isalnum(int c) +{ + return (_ctype_[(unsigned char)(c)] & (_U | _L | _N)); +} + +static inline int isalpha(int c) +{ + return (_ctype_[(unsigned char)(c)] & (_U | _L)); +} + +static inline int iscntrl(int c) +{ + return (_ctype_[(unsigned char)(c)] & (_C)); +} + +static inline int isdigit(int c) +{ + return (_ctype_[(unsigned char)(c)] & (_N)); +} + +static inline int isxdigit(int c) +{ + return (_ctype_[(unsigned char)(c)] & (_N | _X)); +} + +static inline int isspace(int c) +{ + return (_ctype_[(unsigned char)(c)] & (_S)); +} + +static inline int ispunct(int c) +{ + return (_ctype_[(unsigned char)(c)] & (_P)); +} + +static inline int isprint(int c) +{ + return (_ctype_[(unsigned char)(c)] & (_P | _U | _L | _N | _B)); +} + +static inline int isgraph(int c) +{ + return (_ctype_[(unsigned char)(c)] & (_P | _U | _L | _N)); +} + +static inline int islower(int c) +{ + return ((_ctype_[(unsigned char)(c)] & (_U | _L)) == _L); +} + +static inline int isupper(int c) +{ + return ((_ctype_[(unsigned char)(c)] & (_U | _L)) == _U); +} #define isascii(c) ((unsigned)c <= 127) #define toascii(c) ((c)&127)