@@ -3,14 +3,6 @@
#include <xtf/hypercall.h>
#include <xtf/xenstore.h>
-#ifndef isdigit
-/* Avoid pulling in all of ctypes just for this. */
-static int isdigit(int c)
-{
- return c >= '0' && c <= '9';
-}
-#endif
-
void __noreturn panic(const char *fmt, ...)
{
va_list args;
@@ -57,7 +57,7 @@ long strtol(const char *nptr, char **endptr, int base)
s = nptr;
do {
c = *s++;
- } while ( c == ' ' );
+ } while ( isspace(c) );
if (c == '-') {
neg = 1;
c = *s++;
@@ -67,10 +67,7 @@ long strtol(const char *nptr, char **endptr, int base)
c = *s++;
}
if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X') &&
- ((s[1] >= '0' && s[1] <= '9') ||
- (s[1] >= 'A' && s[1] <= 'F') ||
- (s[1] >= 'a' && s[1] <= 'f'))) {
+ c == '0' && (*s == 'x' || *s == 'X') && isxdigit(s[1])) {
c = s[1];
s += 2;
base = 16;
@@ -104,7 +101,7 @@ long strtol(const char *nptr, char **endptr, int base)
cutlim = cutoff % base;
cutoff /= base;
for ( ; ; c = *s++) {
- if (c >= '0' && c <= '9')
+ if (isdigit(c))
c -= '0';
else if (c >= 'A' && c <= 'Z')
c -= 'A' - 10;
@@ -2,14 +2,6 @@
#include <xtf/libc.h>
#include <xtf/compiler.h>
-#ifndef isdigit
-/* Avoid pulling in all of ctypes just for this. */
-static int isdigit(int c)
-{
- return c >= '0' && c <= '9';
-}
-#endif
-
/*
* The subset of formatting supported:
*
@@ -56,6 +56,35 @@ bool arch_fmt_pointer(
char **str, char *end, const char **fmt_ptr, const void *arg,
int width, int precision, unsigned int flags);
+#ifndef isspace
+static inline int isspace(int c)
+{
+ return c == ' ' || c == '\t';
+}
+#endif
+
+#ifndef isdigit
+static inline int isdigit(int c)
+{
+ return c >= '0' && c <= '9';
+}
+#endif
+
+#ifndef isxdigit
+static inline int isxdigit(int c)
+{
+ return (isdigit(c) || (c >= 'A' && c <= 'F') ||
+ (c >= 'a' && c <= 'f'));
+}
+#endif
+
+#ifndef isascii
+static inline int isascii(int c)
+{
+ return c >= 0 && c <= 127;
+}
+#endif
+
#endif /* XTF_LIBC_H */
/*
These ctype.h derived helper functions simplify strtol() code and will help simplify strtoul(). Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de> --- common/lib.c | 8 -------- common/libc/strtol.c | 9 +++------ common/libc/vsnprintf.c | 8 -------- include/xtf/libc.h | 29 +++++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 22 deletions(-)