opendir change: refinement
[minix.git] / lib / libminlib / itoa.c
blob81181b4586e25636b8081b4d290300c1fc7031a2
1 #include <lib.h>
2 /* Integer to ASCII for signed decimal integers. */
4 static int next;
5 static char qbuf[8];
7 char *itoa(int n);
9 char *itoa(n)
10 int n;
12 register int r, k;
13 int flag = 0;
15 next = 0;
16 if (n < 0) {
17 qbuf[next++] = '-';
18 n = -n;
20 if (n == 0) {
21 qbuf[next++] = '0';
22 } else {
23 k = 10000;
24 while (k > 0) {
25 r = n / k;
26 if (flag || r > 0) {
27 qbuf[next++] = '0' + r;
28 flag = 1;
30 n -= r * k;
31 k = k / 10;
34 qbuf[next] = 0;
35 return(qbuf);