minix/lib/nbsd_libminlib/itoa.c
Gianluca Guida 878ba523ac Add libminlib for NBSD libc compilation.
This library includes various random and minix-specific functions
included in the Minix libc. Most of them should be part of libsys,
and in general it would be nice to extinguish this library over
time.
2011-03-22 13:47:35 +00:00

37 lines
496 B
C

#include <lib.h>
/* Integer to ASCII for signed decimal integers. */
PRIVATE int next;
PRIVATE char qbuf[8];
_PROTOTYPE( char *itoa, (int n));
char *itoa(n)
int n;
{
register int r, k;
int flag = 0;
next = 0;
if (n < 0) {
qbuf[next++] = '-';
n = -n;
}
if (n == 0) {
qbuf[next++] = '0';
} else {
k = 10000;
while (k > 0) {
r = n / k;
if (flag || r > 0) {
qbuf[next++] = '0' + r;
flag = 1;
}
n -= r * k;
k = k / 10;
}
}
qbuf[next] = 0;
return(qbuf);
}