summaryrefslogtreecommitdiffstats
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-06-23 15:39:08 -0600
committerSimon Glass <sjg@chromium.org>2015-07-21 17:39:28 -0600
commitc4af6732c4021ffe8b3d0c82bdcf1eebb263bfc3 (patch)
treeb34c0808db76437623e8c1f887ea24d36df91d59 /lib/vsprintf.c
parent1acab96d974a1b9f35cbc901f68ef00653d18738 (diff)
downloadtalos-obmc-uboot-c4af6732c4021ffe8b3d0c82bdcf1eebb263bfc3.tar.gz
talos-obmc-uboot-c4af6732c4021ffe8b3d0c82bdcf1eebb263bfc3.zip
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>
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index a9b8a3ae67..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')
OpenPOWER on IntegriCloud