.TH tempnam() "" "" "General Function (libc)"
.PC "Generate a unique name for a temporary file"
.B "#include <stdio.h>"
\fBchar *tempnam(\fIdirectory\^\fB, \fIname\^\fB);\fR
\fBchar *\fIdirectory\^\fB, *\fIname\^\fB;\fR
.PP
.II "temporary file^generate name"
.II "file^generate name for temporary file"
.II "name^generate for temporary file"
.B tempnam()
constructs a unique temporary name that can be used to name a file.
.I directory
points to
the name of the directory in which you want the temporary file written.
If this variable is NULL,
.B tempnam()
reads the environmental variable
.B TMPDIR
and uses it for
.IR directory .
If neither
.I directory
nor
.B TMPDIR
is given,
.B tempnam()
uses
.BR /tmp .
.PP
.I name
points to the string of letters that will prefix the temporary name.
This string should not be more than three or four characters, to
prevent truncation or duplication of temporary file names.
If
.I name
is NULL,
.B tempnam()
sets it to
.BR t .
.PP
.B tempnam()
uses
.B malloc()
to allocate a buffer for the temporary
file name it returns.
If all goes well,
it returns a pointer to the temporary name it has written.
Otherwise, it returns NULL if the allocation
fails or if it cannot build a temporary file name
successfully.
.SH "See Also"
.Xr "libc," libc
.Xr "mktemp()," mktemp
.Xr "TMPDIR," tmpdir
.Xr "tmpfile()," tmpfile
.Xr "tmpnam()" tmpnam
