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
unistd.h: use long in read() and write() prototypes
[neatlibc.git]
/
mkstemp.c
blob
4173b9daa1ae3d31c142a54de89c4f3102531e7f
1
#include <fcntl.h>
2
#include <string.h>
3
4
static int
tmpid
;
5
static char
*
digs
=
"0123456789abcdef"
;
6
7
int
mkstemp
(
char
*
t
)
8
{
9
char
*
x
=
t
+
strlen
(
t
) -
6
;
10
int
fd
;
11
int
i
;
12
if
(
strlen
(
t
) <
6
)
13
return
-
1
;
14
for
(
i
=
0
;
i
<
6
;
i
++)
15
x
[
i
] =
'0'
;
16
while
((
fd
=
open
(
t
,
O_RDWR
|
O_EXCL
|
O_CREAT
,
0600
)) == -
1
) {
17
int
n
= ++
tmpid
;
18
for
(
i
=
0
;
i
<
6
;
i
++) {
19
x
[
5
-
i
] =
digs
[
n
&
0x0f
];
20
n
<<=
4
;
21
}
22
}
23
unlink
(
t
);
24
return
fd
;
25
}