Index of Section 3 Manual Pages
| Interix / SUA | tempnam.3 | Interix / SUA |
tempnam(3) tempnam(3)
tempnam()
NAME
tempnam() - temporary file routine
SYNOPSIS
#include
char * tempnam (const char *dir, char *pfx)
DESCRIPTION
The tempnam(3) function is similar to tmpnam(3) in that it returns a
pointer to a pathname of a file that does not exist at the time of the
call. Unlike tmpnam(3), you can specify the directory that will contain
the file (dir) if there is no defined temporary directory, and you can
specify the filename's prefix, (pfx).
The tempnam(3) function also looks to use different directories by default
than does tmpnam(3). It determines the directory for the file using the
following steps:
1. The directory used is the directory defined by TMPDIR if it is
writeable.
2. If the previous step does not produce a usable directory, then the
directory used is the directory specified by the dir argument if it
exists and is writeable.
3. If the previous step does not produce a usable directory, then the
directory used is the directory specified by P_tmpdir as declared in
stdio.h if it exists and is writeable.
4. If the previous step does not produce a usable directory, then the
function attempts to use /tmp.
The argument pfx, if non-NULL, is used to specify a file name prefix,
which will be the first part of the created file name. The pfx can be up
to five characters long.
Tempnam(3) allocates space for the string; the pointer can be used in a
call to free(3).
RETURN VALUES
The tempnam(3) function returns a pointer to a file name on success, and a
NULL pointer on error.
ERRORS
The tempnam(3) function may fail and set the global variable errno for
this reason:
[ENOMEM]
There isn't enough memory.
NOTES
Using tempnam(3) is discouraged for these reasons:
1. There can be a race between file name selection and file name
creation.
2. There is no specification for the minimum number of unique temporary
names; some implementations generate as few as 26 before recycling.
3. Some implementations use access(2) to determine whether the temp
file may be created. this can cause problems for use with setuid(2)
and setgid(2) programs.
SEE ALSO
mktemp(3)
tmpfile(3)
USAGE NOTES
The tempnam function is thread safe.
The tempnam function is not async-signal safe.