Serve said:
What's the difference between
char buf[FILENAME_MAX];
strcpy(buf, tmpnam(NULL));
and
char buf[FILENAME_MAX];
tmpnam(buf);
According to my docs both calls write to an internal static buffer.
What's the use of the parameter then (or the internal static buffer)?
from N869:
7.19.4.4 The tmpnam function
Synopsis
[#1]
#include <stdio.h>
char *tmpnam(char *s);
Description
[#2] The tmpnam function generates a string that is a valid
file name and that is not the same as the name of an
existing file.213)
____________________
213Files created using strings generated by the tmpnam
function are temporary only in the sense that their names
should not collide with those generated by conventional
naming rules for the implementation. It is still
necessary to use the remove function to remove such files
when their use is ended, and before program termination.
[#3] The tmpnam function generates a different string each
time it is called, up to TMP_MAX times. If it is called
more than TMP_MAX times, the behavior is implementation-
defined.
[#4] The implementation shall behave as if no library
function calls the tmpnam function.
Returns
[#5] If the argument is a null pointer, the tmpnam function
leaves its result in an internal static object and returns a
pointer to that object. Subsequent calls to the tmpnam
function may modify the same object. If the argument is not
a null pointer, it is assumed to point to an array of at
least L_tmpnam chars; the tmpnam function writes its result
in that array and returns the argument as its value.
Environmental limits
[#6] The value of the macro TMP_MAX shall be at least 25.