tempnam---name for a temporary file
#include <stdio.h> char *tmpnam(char *s); char *tempnam(char *dir, char *pfx); char *_tmpnam_r(void *reent, char *s); char *_tempnam_r(void *reent, char *dir, char *pfx);
Use either of these functions to generate a name for a temporary file. The generated name is guaranteed to avoid collision with other files (for up to
TMP_MAX calls of either function).
tmpnam generates file names with the value of
(defined in `
stdio.h') as the leading directory component of the path.
You can use the
tmpnam argument s to specify a suitable area
of memory for the generated filename; otherwise, you can call
tmpnam(NULL) to use an internal static buffer.
tempnam allows you more control over the generated filename: you
can use the argument dir to specify the path to a directory for
temporary files, and you can use the argument pfx to specify a
prefix for the base filename.
If dir is
tempnam will attempt to use the value of
TMPDIR instead; if there is no such value,
tempnam uses the value of
P_tmpdir (defined in `
If you don't need any particular prefix to the basename of temporary
files, you can pass
NULL as the pfx argument to
_tempnam_r are reentrant versions of
tempnam respectively. The extra argument reent is a
pointer to a reentrancy structure.
The generated filenames are suitable for temporary files, but do not in themselves make files temporary. Files with these names must still be explicitly removed when you no longer want them.
If you supply your own data area s for
tmpnam, you must ensure
that it has room for at least
L_tmpnam elements of type
tempnam return a pointer to the newly
ANSI C requires
tmpnam, but does not specify the use of
P_tmpdir. The System V Interface Definition (Issue 2) requires
Supporting OS subroutines required:
The global pointer
environ is also required.
Go to the first, previous, next, last section, table of contents.