tmpnam_s
Go Up to stdio.h Index
Header File
stdio.h
Category
Input/output Routines
Prototype
errno_t tmpnam_s(char *s, rsize_t maxsize);
Description
Replaces tmpnam adding security enhancements.
tmpnam_s creates a unique file name, which can safely be used as the name of a temporary file. tmpnam_s generates a different string each time you call it, up to TMP_MAX_S times. TMP_MAX_S is defined in stdio.h as 65,535. The length of the strings generated is less than or equal to L_tmpnam_s #define.
The s parameter must not be a null pointer; it is required that s point to an array of at least maxsize length. maxsize must be less than or equal to RSIZE_MAX.
The name tmpnam_s generates is less than maxsize in length and is stored in the array s is pointing to.
Because tmpnam_s is used to set up temporary names in order to create temporary files using them, there are rare circumstances where two identical names can be created. If tmpnam_s is only employed to create temporary files, you should use tmpfile_s instead.
Return Value
tmpnam_s writes the generated string in the array that s is pointing to and returns zero. Otherwise, the function writes a null character to s[0] and returns a nonzero value.
Example
#include <stdio.h> int main(void) { char name[13]; if(std::tmpnam_s(name, 13)){ printf("Unable to create temporary name"); } else{ printf("Temporary name: %s\n", name); } return 0; }
Portability
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
tmpnam_s |
+ |
+ |
+ |
+ |