repo.or.cz
/
minix3.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
remove libcompat_minix as library
[minix3.git]
/
minix
/
lib
/
libminlib
/
itoa.c
blob
ac5a84910ee985156d4e457d99459a7e18105657
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
}