We've been slowly adding ctype functions to different files without even exporting them. Let's change that. Reviewed-by: Nikos Nikoleris <nikos.nikoleris@xxxxxxx> Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx> --- lib/argv.c | 9 +++------ lib/ctype.h | 40 ++++++++++++++++++++++++++++++++++++++++ lib/string.c | 6 +----- 3 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 lib/ctype.h diff --git a/lib/argv.c b/lib/argv.c index 0312d74011d3..9ffa673ef3a1 100644 --- a/lib/argv.c +++ b/lib/argv.c @@ -6,6 +6,7 @@ */ #include "libcflat.h" +#include "ctype.h" #include "argv.h" #include "auxinfo.h" @@ -19,10 +20,6 @@ char **environ = __environ; static char args_copy[1000]; static char *copy_ptr = args_copy; -#define isblank(c) ((c) == ' ' || (c) == '\t') -#define isalpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z') || (c) == '_') -#define isalnum(c) (isalpha(c) || ((c) >= '0' && (c) <= '9')) - static const char *skip_blanks(const char *p) { while (isblank(*p)) @@ -92,12 +89,12 @@ static char *env_next(char *env) if (!*env) return env; - if (isalpha(*env)) { + if (isalpha(*env) || *env == '_') { bool invalid = false; p = env + 1; while (*p && *p != '=' && *p != '\n') { - if (!isalnum(*p)) + if (!(isalnum(*p) || *p == '_')) invalid = true; ++p; } diff --git a/lib/ctype.h b/lib/ctype.h new file mode 100644 index 000000000000..0b43d626478a --- /dev/null +++ b/lib/ctype.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _CTYPE_H_ +#define _CTYPE_H_ + +static inline int isblank(int c) +{ + return c == ' ' || c == '\t'; +} + +static inline int islower(int c) +{ + return c >= 'a' && c <= 'z'; +} + +static inline int isupper(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 isalnum(int c) +{ + return isalpha(c) || isdigit(c); +} + +static inline int isspace(int c) +{ + return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v' || c == '\f'; +} + +#endif /* _CTYPE_H_ */ diff --git a/lib/string.c b/lib/string.c index a3a8f3b1ce0b..6d8a6380db92 100644 --- a/lib/string.c +++ b/lib/string.c @@ -6,6 +6,7 @@ */ #include "libcflat.h" +#include "ctype.h" #include "stdlib.h" #include "linux/compiler.h" @@ -163,11 +164,6 @@ void *memchr(const void *s, int c, size_t n) return NULL; } -static int isspace(int c) -{ - return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v' || c == '\f'; -} - static unsigned long long __strtoll(const char *nptr, char **endptr, int base, bool is_signed, bool is_longlong) { -- 2.34.3