C programming stdio.h function - char *tmpnam(char *str)

www.igif‮t‬idea.com

The tmpnam() function in the stdio.h library of C programming language generates a unique filename that can be used for a temporary file. The generated filename is not guaranteed to be unique, but is usually sufficient for most purposes.

The function has the following prototype:

char *tmpnam(char *str);

The tmpnam() function returns a pointer to a string containing a unique filename. If the argument str is not null, the generated filename is copied to the buffer pointed to by str. The generated filename is a string that consists of the string "tmp" followed by a sequence of characters that is guaranteed to be unique on the system, and ends with a null character.

The tmpnam() function is not thread-safe and should not be used in multithreaded programs. Instead, the tmpnam_r() function should be used, which has the same functionality but is thread-safe.

Note that the tmpnam() function is not recommended for creating temporary files, since the generated filename is not guaranteed to be unique. Instead, the tmpfile() function should be used, which creates a temporary file that is guaranteed to have a unique filename.