The
tmpfile() function returns a pointer to a stream associated with a file descriptor returned by the routine
mkstemp(3). The created file is unlinked before
tmpfile() returns, causing the file to be automatically deleted when the last reference to it is closed. The file is opened with the access value ‘w+'.
The
tmpnam() function returns a pointer to a file name, in the
P_tmpdir directory, which did not reference an existing file at some indeterminate point in the past.
P_tmpdir is defined in the include file
<stdio.h>. If the argument
s is non-
NULL, the file name is copied to the buffer it references. Otherwise, the file name is copied to a static buffer. In either case,
tmpnam() returns a pointer to the file name.
The buffer referenced by
s is expected to be at least
L_tmpnam bytes in length.
L_tmpnam is defined in the include file
<stdio.h>.
The
tempnam() function is similar to
tmpnam(), but provides the ability to specify the directory which will contain the temporary file and the file name prefix.
The environment variable
TMPDIR (if set), the argument
tmpdir (if non-
NULL), the directory
P_tmpdir, and the directory
/tmp are tried, in the listed order, as directories in which to store the temporary file.
The argument
prefix, if non-
NULL, is used to specify a file name prefix, which will be the first part of the created file name.
tempnam() allocates memory in which to store the file name; the returned pointer may be used as a subsequent argument to
free(3).