diff mbox series

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

Message ID 20210723122923.6492-2-roland.gaudig-oss@weidmueller.com
State Accepted
Commit 0b016428a7be4518e4e880536d8ecd8f980fcfd8
Delegated to: Tom Rini
Headers show
Series cmd: setexpr: add fmt format string operation | expand

Commit Message

Roland Gaudig July 23, 2021, 12:29 p.m. UTC
From: Roland Gaudig <roland.gaudig@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@weidmueller.com>
---

(no changes since v1)

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

Comments

Simon Glass July 23, 2021, 9:41 p.m. UTC | #1
On Fri, 23 Jul 2021 at 06:29, Roland Gaudig
<roland.gaudig-oss@weidmueller.com> wrote:
>
> From: Roland Gaudig <roland.gaudig@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@weidmueller.com>
> ---
>
> (no changes since v1)
>
>  include/vsprintf.h | 1 +
>  lib/strto.c        | 8 ++++++++
>  2 files changed, 9 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini July 28, 2021, 2 p.m. UTC | #2
On Fri, Jul 23, 2021 at 12:29:18PM +0000, Roland Gaudig wrote:

> From: Roland Gaudig <roland.gaudig@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@weidmueller.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

For the series, applied to u-boot/master (and enabled on sandbox so the
tests run), thanks!
diff mbox series

Patch

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;