INtime SDK Help

Creates a unique temporary filename or directory.

#include <io.h>

char *mktemp(char *template);
int mkstemp(char *template);
char *mkdtemp(char *template);


Filename template.


Creates a unique filename by modifying a template argument in the form:



Is the part of the new filename that you supply, and the Xs are placeholders for the part supplied by mktemp.

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.

Return values

errno may be set to the following values on failure.
EINVAL - template is NULL or does not contain 'XXXXXX'
ENOTDIR - the base portion of path does not contain a valid directory.
EEXIST - no more temporary files or directories may be created for this process.
On failure, errno may also be set to any of the values set by stat(), open(), or mkdir().


Versions Defined in Include Link to
INtime 3.0 intime/rt/include/io.h io.h clib.lib