.\" Copyright (c) 1988, 1991 The Regents of the University of California.
.\" %sccs.include.redist.man%
.\" @(#)tmpnam.3 5.13 (Berkeley) %G%
.Nd temporary file routines
.Fn tempnam "const char *tmpdir" "const char *prefix"
returns a pointer to a stream associated with a file descriptor returned
The created file is unlinked before
returns, causing the file to be automatically deleted when the last
reference to it is closed.
The file is opened with the access value
returns a pointer to a file name, in the
did not reference an existing file at some indeterminate point in the
is defined in the include file
the file name is copied to the buffer it references.
Otherwise, the file name is copied to a static buffer.
returns a pointer to the file name.
is expected to be at least
is defined in the include file
but provides the ability to specify the directory which will
contain the temporary file and the file name prefix.
are tried, in the listed order, as directories in which to store the
is used to specify a file name prefix, which will be the
first part of the created file name.
allocates memory in which to store the file name; the returned pointer
may be used as a subsequent argument to
returns a pointer to an open file stream on success, and a
return a pointer to a file name on success, and a
may fail and set the global variable
for any of the errors specified for the library functions
for any of the errors specified for the library function
for any of the errors specified for the library functions
These interfaces are provided for System V and
interface is strongly preferred.
There are four important problems with these interfaces (as well as
First, there is an obvious race between file name selection and file
Second, most historic implementations provide only a limited number
of possible temporary file names (usually 26) before file names will
Third, the System V implementations of these functions (and of
function to determine whether or not the temporary file may be created.
This has obvious ramifications for setuid or setgid programs, complicating
the portable use of these interfaces in such programs.
Finally, there is no specification of the permissions with which the
temporary files are created.
This implementation does not have these flaws, but portable software
interface should not be used in software expected to be used on other systems
if there is any possibility that the user does not wish the temporary file to
be publicly readable and writable.