'\"macro stdmacro
.if n .pH g3s.tmpnam @(#)tmpnam	40.15 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} tmpnam 3S "C Programming Language Utilities" "\&"
.if \nX=1 .ds x} tmpnam 3S "C Programming Language Utilities"
.if \nX=2 .ds x} tmpnam 3S "" "\&"
.if \nX=3 .ds x} tmpnam "" "" "\&"
.TH \*(x}
.SH NAME
\f4tmpnam\f1, \f4tempnam\f1 \- create a name for a temporary file
.SH SYNOPSIS
\f4#include <stdio.h>\f1
.PP
\f4char \(**tmpnam (char \(**s);\f1
.PP
\f4char \(**tempnam (const char \(**dir, const char \(**pfx);\f1
.SH DESCRIPTION
These functions generate file names that can safely be used for
a temporary file.
.PP
\f4tmpnam\fP
always generates a file name using the path-prefix defined as
\f4P_tmpdir\f1
in the
\f4<stdio.h>\fP
header file.
If
.I s\^
is
\f4NULL\fP,
\f4tmpnam\fP
leaves its result in an internal static area and returns a pointer
to that area.
The next call to
\f4tmpnam\fP
will destroy the contents of the area.
If
.I s\^
is not
\f4NULL\fP,
it is assumed to be the address of an array of at least
\f4L_tmpnam\f1
bytes, where
\f4L_tmpnam\f1
is a constant defined in
\f4<stdio.h>\fP;
\f4tmpnam\fP
places its result in that array and returns
.IR s .
.P
\f4tempnam\fP
allows the user to control the choice of a directory.
The argument
.I dir\^
points to the name of the directory in which
the file is to be created.
If
.I dir\^
is
\f4NULL\fP
or points to a string that is not a name
for an appropriate directory, the path-prefix defined as
\f4P_tmpdir\^\f1
in the
\f4<stdio.h>\fP
header file is used.
If that directory is not accessible,
\f4\/tmp\f1
will be used as a last resort.
This entire sequence can be up-staged by
providing an environment variable
\f4TMPDIR\f1
in the user's environment, whose value is the name of the
desired temporary-file directory.
.P
Many applications prefer their temporary files to have certain
favorite initial letter sequences in their names.
Use the
.I pfx\^
argument for this.  This argument may be
\f4NULL\fP
or point to a string
of up to five characters to be used as the first few characters of the
temporary-file name.
.P
\f4tempnam\fP
uses
\f4malloc\fP
to get space for the constructed file name,
and returns a pointer to this area.
Thus, any pointer value returned from
\f4tempnam\fP
may serve as an argument to
\f4free\fP
[see
\f4malloc\fP(3C)].
If
\f4tempnam\fP
cannot return the expected result for any reason\(eme.g., \f4malloc\fP
failed\(emor none of the above mentioned attempts to find
an appropriate directory was successful, a
\f4NULL\fP
pointer will be returned.
.PP
\f4tempnam\fP fails if
there is not enough space.
.SH FILES
.TP .7i
\f4p_tmpdir\f1
\f4/var/tmp\f1
.SH SEE ALSO
\f4creat\fP(2), \f4unlink\fP(2),
\f4fopen\fP(3S), \f4malloc\fP(3C), \f4mktemp\fP(3C), \f4tmpfile\fP(3S).
.SH NOTES
These functions generate a different file name each time they are called.
.P
Files created using these functions and either
\f4fopen\fP
or
\f4creat\fP
are temporary only in the sense that they reside in a directory
intended for temporary use, and their names are unique.
It is the user's responsibility to
remove the file when its use is ended.
.PP
If called more than \f4TMP_MAX\fP (defined in \f4stdio.h\fP)
times in a single process,
these functions start recycling previously used names.
.PP
Between the time a file name is created and the file is opened, it
is possible for some other process to create a file with the same name.
This can never happen if that other process is using
these functions or
\f4mktemp\fP
and the file names are chosen to render duplication by other
means unlikely.
.\"	@(#)tmpnam.3s	6.2 of 10/20/83
.Ee
