.TH mktemp() "" "" "General Function (libc)"
.PC "Generate a temporary file name"
\fBchar *mktemp(\fIpattern\fB) char *\fIpattern\fB;\fR
.PP
.II "temporary file^generate name"
.II "file^generate name for temporary file"
.II "name^generate for temporary file"
.B mktemp()
generates a unique file name.
It can be used, for example, to name intermediate data files.
.I pattern
must consist of a string with six
.BR X 's
at the end.
.B mktemp
replaces these
.BR X 's
with the five-digit process id
of the requesting process and a letter that is changed for
each subsequent call.
.B mktemp
returns
.IR pattern .
For example, the call
.DM
	char template[] = "/tmp/sortXXXXXX";
	mktemp(template);
.DE
.PP
might return the name \fB/tmp/sort01234a\fR.
.PP
It is normal practice to write temporary files into the directory
.BR /tmp .
The start of the file name identifies the originator of the file.
.SH "See Also"
.Xr "libc" libc
.SH Notes
Because
.B mktemp()
writes on the argument template,
passing it a quoted string causes a segmentation violation.
To avoid this, either compile the module that contains the call to
.B mktemp()
with the compiler option
.B \-VPSTR
(to put the quoted string into segment
.B .data
rather than into segment
.BR .text )
or, preferably, move the string into the data segment.
For example, use
.DM
	char template[] = "/tmp/sortXXXXXX";
	mktemp(template);
.DE
.PP
rather than:
.DM
	mktemp("/tmp/sortXXXXXX");
.DE
