minix/lib/libminlib/itoa.c
Lionel Sambuc 03514ba605 Getting rid of "old-style-definition"
Patch submitted by hoefnix. Ref.
https://groups.google.com/d/msg/minix-dev/sHQDVJRyx1c/eJjrYOqk5bgJ

Change-Id: I2fcdf4cf119ef252ccc7df06849baf37ffd08440
2014-07-28 17:05:09 +02:00

35 lines
476 B
C

#include <lib.h>
/* Integer to ASCII for signed decimal integers. */
static int next;
static char qbuf[8];
char *itoa(int n);
char *itoa(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);
}