Defined in header
char *tmpnam( char *filename );
errno_t tmpnam_s(char *filename_s, rsize_t maxsize);
filename. The function is capable of generating up to TMP_MAX of unique filenames, but some or all of them may be in use in the filesystem and thus not suitable return values.
filename_sis a null pointer
maxsizeis greater than RSIZE_MAX
maxsizeis less than the generated file name string
- As all bounds-checked functions,
tmpnam_sis only guaranteed to be available of __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including
tmpnam_s modify static state (which may be shared between these functions) and are not required to be thread-safe.
|filename||-||pointer to the character array capable of holding at least L_tmpnam bytes, to be used as a result buffer. If null pointer is passed, a pointer to an internal static buffer is returned.|
|filename_s||-||pointer to the character array capable of holding at least L_tmpnam_s bytes, to be used as a result buffer.|
|maxsize||-|| maximum number of characters the function is allowed to write (typically the size of the |
 Return value
filenamewas not a null pointer. Otherwise a pointer to an internal static buffer is returned. If no suitable filename can be generated, null pointer is returned.
filename_son success. On error, returns non-zero and writes the null character to
filename_sis not null and
maxsizeis not zero and is not greater than RSIZE_MAX).
Although the names generated by
tmpnam are difficult to guess, it is possible that a file with that name is created by another process between the moment
tmpnam returns and the moment this program attempts to use the returned name to create a file. The standard function tmpfile and the POSIX function mkstemp do not have this problem (creating a unique directory using only the standard C library still requires the use of
temporary file name: /tmp/fileRZHMwL temporary file name: /tmp/file420gSN
- C11 standard (ISO/IEC 9899:2011):
- 18.104.22.168 The tmpnam function (p: 303-304)
- K.22.214.171.124 The tmpnam_s function (p: 587-588)