summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/console/vtxprintf.c22
-rw-r--r--src/include/string.h15
2 files changed, 19 insertions, 18 deletions
diff --git a/src/console/vtxprintf.c b/src/console/vtxprintf.c
index f42ed6d077..c429ac79e2 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,8 +161,8 @@ repeat:
/* get field width */
field_width = -1;
- if (is_digit(*fmt)) {
- field_width = skip_atoi(&fmt);
+ if (isdigit(*fmt)) {
+ field_width = skip_atoi((char **)&fmt);
} else if (*fmt == '*') {
++fmt;
/* it's the next argument */
@@ -191,8 +177,8 @@ repeat:
precision = -1;
if (*fmt == '.') {
++fmt;
- if (is_digit(*fmt)) {
- precision = skip_atoi(&fmt);
+ if (isdigit(*fmt)) {
+ precision = skip_atoi((char **)&fmt);
} else if (*fmt == '*') {
++fmt;
/* it's the next argument */
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 */