If you need to use a temporary file in your program, you can use the
tmpfile function to open it. Or you can use the
tmpnam_r) function make a name for a temporary file and
then open it in the
If you need to use a temporary file in your program, you can use the
tmpfile function to open it. Or you can use the
tmpnam_r) function make a name for a temporary file and
then open it in the usual way with
tempnam function is like
tmpnam but lets you choose
what directory temporary files will go in, and something about what
their file names will look like. Important for multi threaded programs
tempnam is reentrant while
tmpnam is not since it
returns a pointer to a static buffer.
These facilities are declared in the header file `stdio.h'.
"wb+". The file is deleted automatically when it is closed or when the program terminates. (On some other ISO C systems the file may fail to be deleted if the program terminates abnormally).
This function is reentrant.
L_tmpnamcharacters, and the result is written into that array.
It is possible for
tmpnam to fail if you call it too many times
without removing previously created files. This is because the fixed
length of a temporary file name gives room for only a finite number of
different names. If
tmpnam fails, it returns a null pointer.
tmpnamfunction. But it does not allow result to be a null pointer. In the later case a null pointer is returned.
This function is reentrant because the non-reentrant situation of
tmpnam cannot happen here.
TMP_MAXis a lower bound for how many temporary names you can create with
tmpnam. You can rely on being able to call
tmpnamat least this many times before it might fail saying you have made too many temporary file names.
With the GNU library, you can create a very large number of temporary
file names--if you actually create the files, you will probably run out
of disk space before you run out of names. Some other systems have a
fixed, small limit on the number of temporary files. The limit is never
malloc; you should release its storage with
freewhen it is no longer needed.
Because the string is dynamically allocated this function is reentrant.
The directory prefix for the temporary file name is determined by testing each of the following, in sequence. The directory must exist and be writable.
TMPDIR, if it is defined. For security reasons this only happens if the program is not SUID or SGID enabled.
This function is defined for SVID compatibility.
Older Unix systems did not have the functions just described. Instead
mkstemp. Both of these functions
work by modifying a file name template string you pass. The last six
characters of this string must be `XXXXXX'. These six `X's
are replaced with six characters which make the whole string a unique
file name. Usually the template string is something like
`/tmp/prefixXXXXXX', and each program uses a unique prefix.
mkstemp modify the
template string, you must not pass string constants to them.
String constants are normally in read-only storage, so your program
would crash when
mkstemp tried to modify the
mktempfunction generates a unique file name by modifying template as described above. If successful, it returns template as modified. If
mktempcannot find a unique file name, it makes template an empty string and returns that. If template does not end with `XXXXXX',
mktempreturns a null pointer.
mkstempfunction generates a unique file name just as
mktempdoes, but it also opens the file for you with
open(see section Opening and Closing Files). If successful, it modifies template in place and returns a file descriptor open on that file for reading and writing. If
mkstempcannot create a uniquely-named file, it makes template an empty string and returns
-1. If template does not end with `XXXXXX',
-1and does not modify template.
mkstemp is actually guaranteed to create a
unique file that cannot possibly clash with any other program trying to
create a temporary file. This is because it works by calling
open with the