Creates a unique temporary filename or directory.
#include <io.h> char *mktemp(char *template); int mkstemp(char *template); char *mkdtemp(char *template);
template
Creates a unique filename by modifying a template argument in the form:
baseXXXXXX
where:
base
This function preserves base and replaces the six trailing X's with two alphanumeric characters followed by a four-digit value. The alphanumeric characters are 0 the first time mktemp is called with a given template. The four-digit value is a unique number based upon the calling thread ID.
In subsequent calls from the same thread with copies of the same template, mktemp checks to see if previously returned names have already been used to create files. If no file exists for a given name, mktemp returns that name. If files exist for all previously returned names, mktemp creates a new name by replacing the alphanumeric characters in the name with the next available lowercase letter. For example, if the first name returned is t006778 and this name is used to create a file, the next name returned will be t0a6778. When creating new names mktemp uses, in order, 0 and then the lowercase letters a through z.
The first call to mktemp modifies the original template. If you call mktemp again with the same template (that is, the original one), an error returns.
mktemp does not create or open files, only filenames. If an error occurs then NULL is returned and errno is set.
mkstemp returns a valid file descriptor if the file could be created. The application must close the descriptor when finished. If an error occurs, -1 is returned and errno is set.
mkdtemp creates a temporary directory and returns its associated path. If an error occurs NULL is returned and errno is set.Versions | Defined in | Include | Link to |
---|---|---|---|
INtime 3.0 | intime/rt/include/io.h | io.h | clib.lib |