diff --git a/lib/libc-gcc.c b/lib/libc-gcc.c index f951433c..a12787b9 100644 --- a/lib/libc-gcc.c +++ b/lib/libc-gcc.c @@ -536,6 +536,34 @@ itoa (int x) return p+1; } +char const* +itoab (int x, int base) +{ + //static char itoa_buf[10]; + //char *p = buf+9; + char *p = itoa_buf; + p += 9; + *p-- = 0; + + //int sign = x < 0; // FIXME + int sign = 0; + if (x < 0) sign = 1; + if (sign) + x = -x; + + do + { + int i = x % base; + *p-- = i > 9 ? 'a' + i - 10 : '0' + i; + x = x / base; + } while (x); + + if (sign && *(p + 1) != '0') + *p-- = '-'; + + return p+1; +} + #if POSIX #define _GNU_SOURCE #include diff --git a/lib/libc-mes.c b/lib/libc-mes.c index 670eaca4..85df77aa 100644 --- a/lib/libc-mes.c +++ b/lib/libc-mes.c @@ -276,6 +276,34 @@ itoa (int x) return p+1; } +char const* +itoab (int x, int base) +{ + //static char itoa_buf[10]; + //char *p = buf+9; + char *p = itoa_buf; + p += 9; + *p-- = 0; + + //int sign = x < 0; // FIXME + int sign = 0; + if (x < 0) sign = 1; + if (sign) + x = -x; + + do + { + int i = x % base; + *p-- = i > 9 ? 'a' + i - 10 : '0' + i; + x = x / base; + } while (x); + + if (sign && *(p + 1) != '0') + *p-- = '-'; + + return p+1; +} + int isdigit (int c) {