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

Go to the source code of this file.

Functions

errno_t tmpnam_s (char *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()

errno_t tmpnam_s ( char *  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
filename_spointer to the character array capable of holding at least L_tmpnam_s bytes, to be used as a result buffer.
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
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).
Note
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 tmpnam).

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).

Definition at line 46 of file tmpnam_s.c.