tmpnam
Creates a unique file name.
Defined in header <stdio.h>
Syntax
#include <stdio.h>
char *tmpnam(char *s);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ | ■ |
Remarks
tmpnam creates a unique file name, which can safely be used as the name of a temporary file, tmpnam generates a different string each time you call
| it, up to TMP_MAX | times. TMP_MAX | is defined in stdio.h as 65,535. |
The parameter to tmpnam, s, is either null or a pointer to an array of at
| least LJmpnam | characters. LJmpnam | is defined in stdio.h. If s is null, |
tmpnam leaves the generated temporary file name in an internal static object and returns a pointer to that object. If s is not null, tmpnam places its result in the pointed-to array, which must be at least LJmpnam characters long, and returns s.
tmpnam creates the temporary file in the directory defined by the TMP environment variable. If TMP is not defined, the TEMP environment variable is used. If neither TMP or TEMP is defined, tmpnam creates the files in the current directory.
If you do create such a temporary file with tmpnam, it is your responsi-bility to delete the file name (for example, with a call to remove). It is not deleted automatically, (tmpfile does delete the file name.)
Return value
| If s is null, tmpnam | returns a pointer to an internal static object. |
| Otherwise, tmpnam | returns s. |
See also
Example
#include <stdio.h>
int main (void)
{
char name [13];
tmpnam (name);
printf ("Temporary name: %s\n", name);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdio.h/tmpnam/
· short form /3.1/tmpnam/