C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
_tempnam, tmpnam
◄Summary► ◄Example► ◄Up► ◄Contents► ◄Index► ◄Back►
─────Run-Time Library───────────────────────────────────────────────────────
The tmpnam function generates a temporary filename that can be
used to open a temporary file without overwriting an existing
file. This name is stored in <string>. If <string> is NULL, tmpnam
leaves the result in an internal static buffer. Thus, any
subsequent calls destroy this value. If <string> is not NULL, it
is assumed to point to an array of at least L_tmpnam bytes. (The
value of L_tmpnam is defined in the STDIO.H include file.) The
function generates unique filenames for up to TMP_MAX calls.
The character string that tmpnam creates consists of the path
prefix defined by the P_tmpdir entry in STDIO.H, followed by a
sequence consisting of the digit characters '0' through '9'. The
numerical value of this string can range from 1 to 65,535.
Changing the definition of L_tmpnam or P_tmpdir in STDIO.H does
not change the operation of tmpnam.
The _tempnam function allows the program to create a temporary
file for use in another directory. This filename will be different
from that of any existing file. The <prefix> argument is the
prefix to the filename. The _tempnam function uses malloc to
allocate space for the filename; the program is responsible for
freeing this space when it is no longer needed.
The _tempnam function looks for the file with the given name in
the following directories, listed in order of precedence:
Directory Used Conditions
Directory specified by TMP TMP environment variable is set,
and directory specified by TMP
exists.
<dir> argument to _tempnam TMP environment variable is not
set, or directory specified by
TMP does not exist.
P_tmpdir in STDIO.H The <dir> argument is NULL, or
<dir> is name of nonexistent
directory.
Current working directory P_tmpdir does not exist.
If the search through the locations listed above fails, _tempnam
returns the value NULL.
Return Value
The tmpnam and _tempnam functions both return a pointer to the
name generated, unless it is impossible to create this name or the
name is not unique. If the name cannot be created or if it already
exists, tmpnam and _tempnam return the value NULL.
-♦-