From 7e5f460ec457fe310156e399198a41eb0ce1e98c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 24 Jul 2021 09:03:29 -0600 Subject: global: Convert simple_strtoul() with hex to hextoul() It is a pain to have to specify the value 16 in each call. Add a new hextoul() function and update the code to use it. Add a proper comment to simple_strtoul() while we are here. Signed-off-by: Simon Glass --- include/vsprintf.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/vsprintf.h b/include/vsprintf.h index 4016de6677..5a268ab5cb 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -10,8 +10,33 @@ #include #include +/** + * simple_strtoul - convert a string to an unsigned long + * + * @param cp The string to be converted + * @param endp Updated to point to the first character not converted + * @param base The number base to use + * @return value decoded from string (0 if invalid) + * + * Converts a string to an unsigned long. If there are invalid characters at + * the end these are ignored. In the worst case, if all characters are invalid, + * 0 is returned + */ ulong simple_strtoul(const char *cp, char **endp, unsigned int base); +/** + * hex_strtoul - convert a string in hex to an unsigned long + * + * @param cp The string to be converted + * @param 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. 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 hextoul(const char *cp, char **endp); + /** * strict_strtoul - convert a string to an unsigned long strictly * @param cp The string to be converted @@ -30,9 +55,6 @@ ulong simple_strtoul(const char *cp, char **endp, unsigned int base); * * echo will append a newline to the tail. * - * simple_strtoul just ignores the successive invalid characters and - * return the converted value of prefix part of the string. - * * Copied this function from Linux 2.6.38 commit ID: * 521cb40b0c44418a4fd36dc633f575813d59a43d * -- cgit v1.2.3