From 3bfb0f719a196558f909ca568f3803f86a190509 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:06 -0600 Subject: lib: Add tests for simple_itoa() Add test and a comment for this function. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin --- include/vsprintf.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'include/vsprintf.h') diff --git a/include/vsprintf.h b/include/vsprintf.h index 83d187e53d4..4479df0af3f 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -172,7 +172,18 @@ int sprintf(char *buf, const char *fmt, ...) * See the vsprintf() documentation for format string extensions over C99. */ int vsprintf(char *buf, const char *fmt, va_list args); -char *simple_itoa(ulong i); + +/** + * simple_itoa() - convert an unsigned integer to a string + * + * This returns a static string containing the decimal representation of the + * given value. The returned value may be overwritten by other calls to the + * same function, so should be used immediately + * + * @val: Value to convert + * @return string containing the decimal representation of @val + */ +char *simple_itoa(ulong val); /** * Format a string and place it in a buffer -- cgit v1.2.3 From 4a255ea3b65e7793eea97a90ad00dc2b59889683 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:07 -0600 Subject: lib: Add a function to convert a string to a hex value Add an xtoa() function, similar to itoa() but for hex instead. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin Tested-by: Artem Lapkin --- include/vsprintf.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'include/vsprintf.h') diff --git a/include/vsprintf.h b/include/vsprintf.h index 4479df0af3f..b4746301462 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -177,14 +177,26 @@ int vsprintf(char *buf, const char *fmt, va_list args); * simple_itoa() - convert an unsigned integer to a string * * This returns a static string containing the decimal representation of the - * given value. The returned value may be overwritten by other calls to the - * same function, so should be used immediately + * given value. The returned value may be overwritten by other calls to other + * simple_... functions, so should be used immediately * * @val: Value to convert * @return string containing the decimal representation of @val */ char *simple_itoa(ulong val); +/** + * simple_xtoa() - convert an unsigned integer to a hex string + * + * This returns a static string containing the hexadecimal representation of the + * given value. The returned value may be overwritten by other calls to other + * simple_... functions, so should be used immediately + * + * @val: Value to convert + * @return string containing the hexecimal representation of @val + */ +char *simple_xtoa(ulong num); + /** * Format a string and place it in a buffer * -- cgit v1.2.3