Commit 3cce8a5496452285e1828984ad3945417205cfc3

Authored by Simon Glass
Committed by Wolfgang Denk
1 parent 70d52f9a4e

Move simple_itoa to vsprintf

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

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 3 changed files with 17 additions and 15 deletions Side-by-side Diff

... ... @@ -17,7 +17,6 @@
17 17 * Erik W. Troan, which they placed in the public domain. I don't know
18 18 * how much of the Johnson/Troan code has survived the repeated rewrites.
19 19 * Other credits:
20   - * simple_itoa() was lifted from boa-0.93.15
21 20 * b_addchr() derived from similar w_addchar function in glibc-2.2
22 21 * setup_redirect(), redirect_opt_num(), and big chunks of main()
23 22 * and many builtins derived from contributions by Erik Andersen
... ... @@ -920,20 +919,6 @@
920 919 if (rc) return rc;
921 920 }
922 921 return b_addchr(o, ch);
923   -}
924   -
925   -/* belongs in utility.c */
926   -char *simple_itoa(unsigned int i)
927   -{
928   - /* 21 digits plus null terminator, good for 64-bit or smaller ints */
929   - static char local[22];
930   - char *p = &local[21];
931   - *p-- = '\0';
932   - do {
933   - *p-- = '0' + i % 10;
934   - i /= 10;
935   - } while (i > 0);
936   - return p + 1;
937 922 }
938 923  
939 924 #ifndef __U_BOOT__
... ... @@ -723,6 +723,7 @@
723 723 int sprintf(char * buf, const char *fmt, ...)
724 724 __attribute__ ((format (__printf__, 2, 3)));
725 725 int vsprintf(char *buf, const char *fmt, va_list args);
  726 +char *simple_itoa(ulong i);
726 727  
727 728 /* lib/strmhz.c */
728 729 char * strmhz(char *buf, unsigned long hz);
... ... @@ -7,6 +7,8 @@
7 7 /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
8 8 /*
9 9 * Wirzenius wrote this portably, Torvalds fucked it up :-)
  10 + *
  11 + * from hush: simple_itoa() was lifted from boa-0.93.15
10 12 */
11 13  
12 14 #include <stdarg.h>
... ... @@ -737,5 +739,19 @@
737 739 /* This will not return */
738 740 panic("%s:%u: %s: Assertion `%s' failed.", file, line, function,
739 741 assertion);
  742 +}
  743 +
  744 +char *simple_itoa(ulong i)
  745 +{
  746 + /* 21 digits plus null terminator, good for 64-bit or smaller ints */
  747 + static char local[22];
  748 + char *p = &local[21];
  749 +
  750 + *p-- = '\0';
  751 + do {
  752 + *p-- = '0' + i % 10;
  753 + i /= 10;
  754 + } while (i > 0);
  755 + return p + 1;
740 756 }