Hello Patrick Rudolph,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/32858
to review the following change.
Change subject: console: Move poor-man's atoi() into string.h ......................................................................
console: Move poor-man's atoi() into string.h
vtxprintf.c seems to have been written before string.h was as fleshed out as it is today -- this patch removes some custom implementation of stuff we now have globally. It also moves the skip_atoi() function into string.h, because I need it somewhere else, and while we maybe don't want a huge fully-featured string parsing library in coreboot, being able to parse an integer is occasionally useful.
Change-Id: Iecb2b970aecfc768540d2bf8b3023445f54853a4 Signed-off-by: Julius Werner jwerner@chromium.org --- M src/console/vtxprintf.c M src/include/string.h 2 files changed, 14 insertions(+), 16 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/58/32858/1
diff --git a/src/console/vtxprintf.c b/src/console/vtxprintf.c index f42ed6d..74159d6 100644 --- a/src/console/vtxprintf.c +++ b/src/console/vtxprintf.c @@ -24,20 +24,6 @@ #define SUPPORT_64BIT_INTS #endif
-/* haha, don't need ctype.c */ -#define isdigit(c) ((c) >= '0' && (c) <= '9') -#define is_digit isdigit -#define isxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) - -static int skip_atoi(const char **s) -{ - int i = 0; - - while (is_digit(**s)) - i = i*10 + *((*s)++) - '0'; - return i; -} - #define ZEROPAD 1 /* pad with zero */ #define SIGN 2 /* unsigned/signed long */ #define PLUS 4 /* show plus */ @@ -175,7 +161,7 @@
/* get field width */ field_width = -1; - if (is_digit(*fmt)) { + if (isdigit(*fmt)) { field_width = skip_atoi(&fmt); } else if (*fmt == '*') { ++fmt; @@ -191,7 +177,7 @@ precision = -1; if (*fmt == '.') { ++fmt; - if (is_digit(*fmt)) { + if (isdigit(*fmt)) { precision = skip_atoi(&fmt); } else if (*fmt == '*') { ++fmt; diff --git a/src/include/string.h b/src/include/string.h index 4a2f5e9..c8de568 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -178,4 +178,16 @@ c -= 'A'-'a'; return c; } + +/* Parses a positive integer and moves the input pointer forward to the first + character that's not a valid digit. */ +static inline int skip_atoi(const char **s) +{ + int i = 0; + + while (isdigit(**s)) + i = i*10 + *((*s)++) - '0'; + return i; +} + #endif /* STRING_H */