[PATCH kvm-unit-tests 2/2] lib: Add ctype.h and collect is* functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We've been slowly adding ctype functions to different files without
even exporting them. Let's change that.

Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 lib/argv.c   |  7 ++-----
 lib/ctype.h  | 40 ++++++++++++++++++++++++++++++++++++++++
 lib/string.c |  6 +-----
 3 files changed, 43 insertions(+), 10 deletions(-)
 create mode 100644 lib/ctype.h

diff --git a/lib/argv.c b/lib/argv.c
index 0312d74011d3..951b176ae8b1 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,7 +89,7 @@ static char *env_next(char *env)
 	if (!*env)
 		return env;
 
-	if (isalpha(*env)) {
+	if (isalpha(*env) || *env == '_') {
 		bool invalid = false;
 
 		p = env + 1;
diff --git a/lib/ctype.h b/lib/ctype.h
new file mode 100644
index 000000000000..ce787a60cdf3
--- /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




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux