[U-Boot] [PATCH v2 01/11] Move simple_itoa() to vsprintf.c

Simon Glass sjg at chromium.org
Tue Oct 25 05:59:58 CEST 2011


This function is generally useful and shouldn't hide away in hush. It
has been moved as is.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 common/hush.c    |   15 ---------------
 include/common.h |    1 +
 lib/vsprintf.c   |   16 ++++++++++++++++
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/common/hush.c b/common/hush.c
index 940889b..2495a6d 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -17,7 +17,6 @@
  *      Erik W. Troan, which they placed in the public domain.  I don't know
  *      how much of the Johnson/Troan code has survived the repeated rewrites.
  * Other credits:
- *      simple_itoa() was lifted from boa-0.93.15
  *      b_addchr() derived from similar w_addchar function in glibc-2.2
  *      setup_redirect(), redirect_opt_num(), and big chunks of main()
  *        and many builtins derived from contributions by Erik Andersen
@@ -922,20 +921,6 @@ static int b_addqchr(o_string *o, int ch, int quote)
 	return b_addchr(o, ch);
 }
 
-/* belongs in utility.c */
-char *simple_itoa(unsigned int i)
-{
-	/* 21 digits plus null terminator, good for 64-bit or smaller ints */
-	static char local[22];
-	char *p = &local[21];
-	*p-- = '\0';
-	do {
-		*p-- = '0' + i % 10;
-		i /= 10;
-	} while (i > 0);
-	return p + 1;
-}
-
 #ifndef __U_BOOT__
 static int b_adduint(o_string *o, unsigned int i)
 {
diff --git a/include/common.h b/include/common.h
index a1683a2..4329802 100644
--- a/include/common.h
+++ b/include/common.h
@@ -723,6 +723,7 @@ void	panic(const char *fmt, ...)
 int	sprintf(char * buf, const char *fmt, ...)
 		__attribute__ ((format (__printf__, 2, 3)));
 int	vsprintf(char *buf, const char *fmt, va_list args);
+char *simple_itoa(ulong i);
 
 /* lib/strmhz.c */
 char *	strmhz(char *buf, unsigned long hz);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 79dead3..e497a86 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -7,6 +7,8 @@
 /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
 /*
  * Wirzenius wrote this portably, Torvalds fucked it up :-)
+ *
+ * from hush: simple_itoa() was lifted from boa-0.93.15
  */
 
 #include <stdarg.h>
@@ -738,3 +740,17 @@ void __assert_fail(const char *assertion, const char *file, unsigned line,
 	panic("%s:%u: %s: Assertion `%s' failed.", file, line, function,
 	      assertion);
 }
+
+char *simple_itoa(ulong i)
+{
+	/* 21 digits plus null terminator, good for 64-bit or smaller ints */
+	static char local[22];
+	char *p = &local[21];
+
+	*p-- = '\0';
+	do {
+		*p-- = '0' + i % 10;
+		i /= 10;
+	} while (i > 0);
+	return p + 1;
+}
-- 
1.7.3.1



More information about the U-Boot mailing list