char * tmpnam ( char * str );
Generate temporary filename
Returns a string containing a file name different from the name of any existing file, and thus suitable to safely create a temporary file without risking to overwrite an existing file.
If str is a null pointer, the resulting string is stored in an internal static array that can be accessed by the return value. The content of this string is preserved at least until a subsequent call to this same function, which may overwrite it.
If str is not a null pointer, it shall point to an array of at least L_tmpnam characters that will be filled with the proposed temporary file name.
The file name returned by this function can be used to create a regular file using fopen to be used as a temporary file. The file created this way, unlike those created with tmpfile is not automatically deleted when closed; A program shall call remove to delete this file once closed.
- Pointer to an array of characters where the proposed temporary name will be stored as a C string. The size of this array should be at least L_tmpnam characters.
Alternativelly, a null pointer can be specified to use an internal static array to store the proposed temporary name, whose pointer is returned by the function.
On success, a pointer to the C string containing the proposed name for a temporary file:
If the function fails to create a suitable filename, it returns a null pointer.
- If str was a null pointer, this points to an internal buffer (whose content is preserved at least until the next call to this function).
- If str was not a null pointer, str is returned.
/* tmpnam example */
int main ()
char buffer [L_tmpnam];
char * pointer;
printf ("Tempname #1: %s\n",buffer);
pointer = tmpnam (NULL);
printf ("Tempname #2: %s\n",pointer);
This program will generate two different names for temporary files. Each one has been created by one of the two methods in which tmpnam can be used.
Tempname #1: /s4s4.
Tempname #2: /s4s4.1
- Open file (function
- Open a temporary file (function