xref: /minix/minix/lib/libc/gen/itoa.c (revision 83133719)
1 #include <lib.h>
2 /* Integer to ASCII for signed decimal integers. */
3 
4 static int next;
5 static char qbuf[8];
6 
7 char *itoa(int n);
8 
9 char *itoa(int n)
10 {
11   register int r, k;
12   int flag = 0;
13 
14   next = 0;
15   if (n < 0) {
16 	qbuf[next++] = '-';
17 	n = -n;
18   }
19   if (n == 0) {
20 	qbuf[next++] = '0';
21   } else {
22 	k = 10000;
23 	while (k > 0) {
24 		r = n / k;
25 		if (flag || r > 0) {
26 			qbuf[next++] = '0' + r;
27 			flag = 1;
28 		}
29 		n -= r * k;
30 		k = k / 10;
31 	}
32   }
33   qbuf[next] = 0;
34   return(qbuf);
35 }
36