aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSimon Glass2021-07-24 09:03:29 -0600
committerTom Rini2021-08-02 13:32:14 -0400
commit7e5f460ec457fe310156e399198a41eb0ce1e98c (patch)
tree7e89e4d15fcea2d2263c4b4af1be69905537ef42 /include
parent031725f8cdf33e836d19f35d3fe82c5baa5a2976 (diff)
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 <sjg@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/vsprintf.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/include/vsprintf.h b/include/vsprintf.h
index 4016de6677a..5a268ab5cb3 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -10,9 +10,34 @@
#include <stdarg.h>
#include <linux/types.h>
+/**
+ * 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
* @param base The number base to use
@@ -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
*