X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Fvsprintf.c;h=4c82837cc41e8e55899d945e8f27d399a0b0be71;hb=bcbb6448b937d93179ce267fa536a81d867cbf2e;hp=bedc865240de0dd7a2d50fa9be5a73dce5084b7b;hpb=e536ab8849b2b4f6d68bbc8e1d1f9bc033db06bd;p=oweals%2Fu-boot.git diff --git a/lib/vsprintf.c b/lib/vsprintf.c index bedc865240..4c82837cc4 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -166,6 +166,25 @@ unsigned long long simple_strtoull(const char *cp, char **endp, return result; } +long trailing_strtoln(const char *str, const char *end) +{ + const char *p; + + if (!end) + end = str + strlen(str); + for (p = end - 1; p > str; p--) { + if (!isdigit(*p)) + return simple_strtoul(p + 1, NULL, 10); + } + + return -1; +} + +long trailing_strtol(const char *str) +{ + return trailing_strtoln(str, NULL); +} + /* we use this so that we can do without the ctype library */ #define is_digit(c) ((c) >= '0' && (c) <= '9') @@ -909,3 +928,19 @@ void print_grouped_ull(unsigned long long int_val, int digits) grab = 3; } } + +bool str2off(const char *p, loff_t *num) +{ + char *endptr; + + *num = simple_strtoull(p, &endptr, 16); + return *p != '\0' && *endptr == '\0'; +} + +bool str2long(const char *p, ulong *num) +{ + char *endptr; + + *num = simple_strtoul(p, &endptr, 16); + return *p != '\0' && *endptr == '\0'; +}