mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 10:39:08 +00:00
lib: Add function to extract a number from the end of a string
Split out the code in fdtdec which finds a number at the end of a string. It can be useful in other situations. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
1acab96d97
commit
c4af6732c4
3 changed files with 51 additions and 8 deletions
|
@ -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')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue