Or login with:
#include <stdio.h>
| FILE | tmpfile (void) |
| char | tmpnam (char *str) |
| char | tempnam (const char *tmpdir, const char *prefix) |
#include <stdio.h> int main() { // create a temporary binary file // using the "wb+" access parameters FILE *f = tmpfile(); // ...use the temporary file... // close and delete the temporary file fclose(f); return 0; }The tmpnam function returns a pointer to a file name, in the <span class="Dv">P_tmpdir</span> directory, which did not reference an existing file at some indeterminate point in the past. <span class="Dv">P_tmpdir</span> is defined in the include file #include <stdio.h> If the argument \c str is non- <span class="Dv">NULL</span>, 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. \n \n The buffer referenced by \c str is expected to be at least <span class="Dv">L_tmpnam</span> bytes in length. <span class="Dv">L_tmpnam</span> is defined in the include file #include <stdio.h> \n \n 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. \n \n The environment variable <span class="Ev">TMPDIR</span> (if set), the argument \c tmpdir (if non- <span class="Dv">NULL</span>), the directory <span class="Dv">P_tmpdir</span>, and the directory <span class="Pa">/tmp</span> are tried, in the listed order, as directories in which to store the temporary file. \n \n The argument \c prefix, if non- <span class="Dv">NULL</span>, is used to specify a file name prefix, which will be the first part of the created file name. The tempnam function allocates memory in which to store the file name; the returned pointer may be used as a subsequent argument to free.
access system call to determine whether or not the temporary file may be created. This has obvious ramifications for setuid or setgid programs, complicating the portable use of these interfaces in such programs. \n
\n
The tmpfile interface should not be used in software expected to be used on other systems if there is any possibility that the user does not wish the temporary file to be publicly readable and writable.You must login to leave a messge