From: Heinrich Schuchardt Date: Sun, 3 Nov 2024 22:42:20 +0000 (+0100) Subject: lib: provide function hextoull() X-Git-Url: http://git.dujemihanovic.xyz/login.html?a=commitdiff_plain;h=8ff37ec010ee228c0f7627b43e225103d9f460db;p=u-boot.git lib: provide function hextoull() We often convert hexadecimal strings to hextoull(). Provide a wrapper function to simple_strtoull() that does not require specifying the radix. Signed-off-by: Heinrich Schuchardt Reviewed-by: Patrick Delaunay Reviewed-by: Ilias Apalodimas --- diff --git a/include/vsprintf.h b/include/vsprintf.h index fe95147142..9da6ce7cc4 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -44,6 +44,19 @@ ulong simple_strtoul(const char *cp, char **endp, unsigned int base); */ unsigned long hextoul(const char *cp, char **endp); +/** + * hex_strtoull - convert a string in hex to an unsigned long long + * + * @cp: The string to be converted + * @endp: Updated to point to the first character not converted + * Return: value decoded from string (0 if invalid) + * + * Converts a hex string to an unsigned long long. If there are invalid + * characters at the end these are ignored. In the worst case, if all characters + * are invalid, 0 is returned + */ +unsigned long long hextoull(const char *cp, char **endp); + /** * dec_strtoul - convert a string in decimal to an unsigned long * diff --git a/lib/strto.c b/lib/strto.c index f83ac67c66..206d1e9184 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -78,6 +78,11 @@ ulong hextoul(const char *cp, char **endp) return simple_strtoul(cp, endp, 16); } +unsigned long long hextoull(const char *cp, char **endp) +{ + return simple_strtoull(cp, endp, 16); +} + ulong dectoul(const char *cp, char **endp) { return simple_strtoul(cp, endp, 10);