repo.or.cz
/
neatlibc.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
malloc: more compact memory pools
[neatlibc.git]
/
mkstemp.c
blob
c9c400397443d21f71e09b9bf02c02c097ef6a2b
1
#include <fcntl.h>
2
#include <string.h>
3
#include <unistd.h>
4
5
static int
tmpid
;
6
static char
*
digs
=
"0123456789abcdef"
;
7
8
int
mkstemp
(
char
*
t
)
9
{
10
char
*
x
=
t
+
strlen
(
t
) -
6
;
11
int
fd
;
12
int
i
;
13
if
(
strlen
(
t
) <
6
)
14
return
-
1
;
15
for
(
i
=
0
;
i
<
6
;
i
++)
16
x
[
i
] =
'0'
;
17
while
((
fd
=
open
(
t
,
O_RDWR
|
O_EXCL
|
O_CREAT
,
0600
)) == -
1
) {
18
int
n
= ++
tmpid
;
19
for
(
i
=
0
;
i
<
6
;
i
++) {
20
x
[
5
-
i
] =
digs
[
n
&
0x0f
];
21
n
<<=
4
;
22
}
23
}
24
unlink
(
t
);
25
return
fd
;
26
}