summaryrefslogtreecommitdiff
path: root/src/include/string.h
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2019-05-13 17:45:27 -0700
committerPatrick Georgi <pgeorgi@google.com>2019-05-23 08:43:12 +0000
commit66c77c2dc9b16d3b3522697ea04009aad1c8ba79 (patch)
treead10231da105645e9002a9d5b11bd1e855f18e22 /src/include/string.h
parent2b6da7f326bf84a8eab3684edf5e5814e9c23385 (diff)
downloadcoreboot-66c77c2dc9b16d3b3522697ea04009aad1c8ba79.tar.xz
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 makes the skip_atoi() function globally available, 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> Reviewed-on: https://review.coreboot.org/c/coreboot/+/32858 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Alex Thiessen <alex.thiessen.de+coreboot@gmail.com>
Diffstat (limited to 'src/include/string.h')
-rw-r--r--src/include/string.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/include/string.h b/src/include/string.h
index 4a2f5e9ee6..c56a760a04 100644
--- a/src/include/string.h
+++ b/src/include/string.h
@@ -178,4 +178,19 @@ static inline int tolower(int c)
c -= 'A'-'a';
return c;
}
+
+/*
+ * Parses an unsigned integer and moves the input pointer forward to the first
+ * character that's not a valid digit. s and *s must not be NULL. Result
+ * undefined if it overruns the return type size.
+ */
+static inline unsigned int skip_atoi(char **s)
+{
+ unsigned int i = 0;
+
+ while (isdigit(**s))
+ i = i*10 + *((*s)++) - '0';
+ return i;
+}
+
#endif /* STRING_H */