mlibc: Tinycc support: itoab, for debugging.

* lib/libc-gcc.c (itoab): New function.
* lib/libc-mes.c (itoab): New function.
This commit is contained in:
Jan Nieuwenhuizen 2017-12-03 10:33:05 +01:00
parent 3636818b1a
commit d7b35f6b1e
2 changed files with 56 additions and 0 deletions

View file

@ -536,6 +536,34 @@ itoa (int x)
return p+1; 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 #if POSIX
#define _GNU_SOURCE #define _GNU_SOURCE
#include <assert.h> #include <assert.h>

View file

@ -276,6 +276,34 @@ itoa (int x)
return p+1; 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 int
isdigit (int c) isdigit (int c)
{ {