safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
tmpnam_s.c File Reference
#include "safe_lib.h"
+ Include dependency graph for tmpnam_s.c:

Functions

EXPORT errno_t tmpnam_s (char *filename_s, rsize_t maxsize)
 Creates a unique valid file name (no longer than L_tmpnam in length) and stores it in character string pointed to by filename. More...
 

Function Documentation

◆ tmpnam_s()

EXPORT errno_t tmpnam_s ( char *  filename_s,
rsize_t  maxsize 
)

Creates a unique valid file name (no longer than L_tmpnam in length) and stores it in character string pointed to by filename.

The function is capable of generating up to TMP_MAX_S of unique filenames, but some or all of them may be in use in the filesystem and thus not suitable return values.

Remarks
SPECIFIED IN
Parameters
[out]filename_spointer to the character array capable of holding at least L_tmpnam_s bytes, to be used as a result buffer.
[in]maxsizemaximum number of characters the function is allowed to write (typically the size of the filename_s array).
Precondition
No more than TMP_MAX_S files may be opened
filename_s is a null pointer
maxsize is greater than RSIZE_MAX_STR
maxsize is less than the generated file name string
Returns
Returns zero and writes the file name to filename_s on success. On error, returns non-zero and writes the null character to filename_s[0] (only if filename_s is not null and maxsize is not zero and is not greater than RSIZE_MAX_STR).
Return values
EOKon success
ESNULLPwhen filename_s is a NULL pointer
ESZEROLwhen maxsize = 0
ESLEMAXwhen maxsize > RSIZE_MAX_STR or more than TMP_MAX_S files were opened.
errno()when tmpnam() failed, typically -ENOENT
Note
Although the names generated by tmpnam_s 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 tmpnam_s).

POSIX systems additionally define the similarly named function tempnam(), which offers the choice of a directory (which defaults to the optionally defined macro P_tmpdir).