<s>
In	O
computing	O
,	O
mkstemp	B-Language
is	O
a	O
POSIX	O
function	O
for	O
creating	O
a	O
temporary	B-Application
file	I-Application
(	O
a	O
computer	B-Operating_System
file	I-Operating_System
which	O
usually	O
ceases	O
to	O
exist	O
when	O
the	O
program	B-Application
,	O
which	O
opened	O
the	O
file	O
,	O
closes	O
it	O
or	O
terminates	O
)	O
.	O
</s>
<s>
It	O
accepts	O
an	O
argument	O
that	O
determines	O
the	O
location	O
of	O
the	O
temporary	B-Application
file	I-Application
,	O
and	O
the	O
prefix	O
of	O
its	O
generated	O
filename	O
.	O
</s>
<s>
After	O
mkstemp	B-Language
was	O
added	O
to	O
the	O
Single	O
UNIX	O
Specification	O
,	O
the	O
function	O
tempnam( )	O
was	O
deprecated	O
,	O
because	O
the	O
latter	O
carried	O
the	O
risk	O
that	O
a	O
temporary	B-Application
file	I-Application
with	O
the	O
same	O
name	O
could	O
be	O
created	O
by	O
another	O
thread	O
or	O
process	O
within	O
the	O
time	O
from	O
when	O
the	O
caller	O
obtains	O
the	O
temporary	O
filename	O
and	O
attempts	O
to	O
create	O
it	O
.	O
</s>
<s>
mkstemp	B-Language
does	O
not	O
suffer	O
from	O
this	O
problem	O
.	O
</s>
<s>
int	O
mkstemp( char*	O
template	O
)	O
;	O
</s>
<s>
The	O
contents	O
of	O
template	O
must	O
be	O
in	O
the	O
format	O
of	O
a	O
valid	O
file	B-Application
path	I-Application
,	O
with	O
six	O
trailing	O
'	O
X	O
's	O
.	O
</s>
<s>
The	O
parameter	O
template	O
must	O
not	O
have	O
been	O
used	O
in	O
a	O
previous	O
invocation	O
of	O
mkstemp	B-Language
.	O
</s>
<s>
The	O
trailing	O
'	O
X	O
's	O
in	O
template	O
are	O
overwritten	O
to	O
generate	O
a	O
unique	O
file	B-Application
name	I-Application
for	O
the	O
resulting	O
temporary	B-Application
file	I-Application
.	O
</s>
<s>
The	O
function	O
reports	O
a	O
valid	O
file	B-Application
descriptor	I-Application
to	O
a	O
temporary	B-Application
file	I-Application
on	O
success	O
;	O
on	O
failure	O
,	O
it	O
reports	O
-1	O
.	O
</s>
<s>
The	O
following	O
code	O
is	O
an	O
example	O
of	O
the	O
usage	O
of	O
mkstemp	B-Language
;	O
the	O
local	O
variable	O
filename	O
is	O
modified	O
by	O
mkstemp	B-Language
and	O
will	O
contain	O
the	O
path	O
to	O
the	O
new	O
file	O
:	O
</s>
<s>
It	O
is	O
unspecified	O
if	O
mkstemp	B-Language
sets	O
errno	B-Error_Name
,	O
and	O
what	O
values	O
of	O
errno	B-Error_Name
are	O
set	O
,	O
in	O
the	O
event	O
of	O
failure	O
.	O
</s>
<s>
The	O
mkstemp	B-Language
function	O
generates	O
a	O
filename	O
according	O
to	O
the	O
supplied	O
argument	O
for	O
the	O
template	O
,	O
and	O
attempts	O
to	O
create	O
it	O
.	O
</s>
<s>
After	O
this	O
,	O
it	O
opens	O
the	O
file	O
and	O
returns	O
the	O
file	B-Application
descriptor	I-Application
to	O
the	O
caller	O
,	O
with	O
the	O
data	B-General_Concept
buffer	I-General_Concept
that	O
was	O
passed	O
to	O
the	O
function	O
with	O
the	O
template	O
now	O
containing	O
the	O
new	O
filename	O
.	O
</s>
<s>
The	O
file	O
can	O
be	O
deleted	O
immediately	O
after	O
the	O
mkstemp	B-Language
call	O
returns	O
to	O
prevent	O
other	O
processes	O
from	O
opening	O
it	O
,	O
but	O
the	O
file	O
can	O
still	O
be	O
used	O
because	O
the	O
calling	O
process	O
will	O
still	O
have	O
a	O
valid	O
file	B-Application
descriptor	I-Application
.	O
</s>
<s>
Older	O
versions	O
of	O
mkstemp	B-Language
created	O
the	O
file	O
with	O
an	O
umask	O
of	O
0666	O
,	O
resulting	O
in	O
the	O
temporary	B-Application
files	I-Application
being	O
readable	O
and	O
writable	O
to	O
all	O
users	O
,	O
and	O
thus	O
presenting	O
a	O
security	O
vulnerability	O
;	O
this	O
is	O
mitigated	O
by	O
setting	O
the	O
umask	O
manually	O
before	O
calling	O
mkstemp	B-Language
.	O
</s>
