![]() |
![]() |
![]() |
Create a name for a temporary file
#include <stdio.h> char* tempnam( const char* dir, const char* pfx );
libc
The tempnam() function generates a pathname for use as a temporary file. The pathname is in the directory specified by dir and has the prefix specified in pfx.
If dir is NULL, the pathname is prefixed with the first accessible directory contained in:
If all of these paths are inaccessible, tempnam() attempts to use /tmp and then the current working directory.
If pfx isn't NULL, the string it points to must be <=5 bytes long.
The tempnam() function generates up to TMP_MAX unique file names before it starts to recycle them.
A pointer to the generated file name, which should be deallocated with the free() function when the application no longer needs it, or NULL if an error occurs.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | No |
The tempnam() functions creates only pathnames; the application must create and remove the files.
It's possible for another thread or process to create a file with the same name between the time the pathname is created and the file is opened.
free(), tmpfile(), tmpnam(), unlink()
![]() |
![]() |
![]() |