[PATCH v3 1/6] lib: strto: add simple_strtoll function

Roland Gaudig roland.gaudig-oss at weidmueller.com
Fri Jul 23 14:29:18 CEST 2021


From: Roland Gaudig <roland.gaudig at weidmueller.com>

Add simple_strtoll function for converting a string containing digits
into a long long int value.

Signed-off-by: Roland Gaudig <roland.gaudig at weidmueller.com>
---

(no changes since v1)

 include/vsprintf.h | 1 +
 lib/strto.c        | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/vsprintf.h b/include/vsprintf.h
index 2290083eba..4016de6677 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -41,6 +41,7 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
 unsigned long long simple_strtoull(const char *cp, char **endp,
 					unsigned int base);
 long simple_strtol(const char *cp, char **endp, unsigned int base);
+long long simple_strtoll(const char *cp, char **endp, unsigned int base);
 
 /**
  * trailing_strtol() - extract a trailing integer from a string
diff --git a/lib/strto.c b/lib/strto.c
index c00bb5895d..f8b53d846b 100644
--- a/lib/strto.c
+++ b/lib/strto.c
@@ -143,6 +143,14 @@ unsigned long long simple_strtoull(const char *cp, char **endp,
 	return result;
 }
 
+long long simple_strtoll(const char *cp, char **endp, unsigned int base)
+{
+	if (*cp == '-')
+		return -simple_strtoull(cp + 1, endp, base);
+
+	return simple_strtoull(cp, endp, base);
+}
+
 long trailing_strtoln(const char *str, const char *end)
 {
 	const char *p;
-- 
2.25.1



More information about the U-Boot mailing list