mescc: Mes C Library: Use __mesabi_uldiv.

* lib/mes/ntoab.c (ntoab): Use __mesabi_uldiv.
This commit is contained in:
Danny Milosavljevic 2019-06-14 01:02:40 +02:00 committed by Jan Nieuwenhuizen
parent cc870b4adc
commit c35124ab54
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 9 additions and 6 deletions

View File

@ -26,24 +26,27 @@ ntoab (long x, int base, int signed_p)
static char itoa_buf[20];
char *p = itoa_buf + 11;
*p-- = 0;
assert(base > 0);
int sign = 0;
unsigned long u = x;
int sign_p = 0;
unsigned long u;
if (signed_p && x < 0)
{
sign = 1;
sign_p = 1;
u = -x;
}
else
u = x;
do
{
long i = u % base;
unsigned long i;
u = __mesabi_uldiv(u, (unsigned long) base, &i);
*p-- = i > 9 ? 'a' + i - 10 : '0' + i;
u = u / base;
}
while (u);
if (sign && *(p + 1) != '0')
if (sign_p && *(p + 1) != '0')
*p-- = '-';
return p + 1;