char *mkdtemp(char *template);
int mkstemp(char *template);
int mkstemp64(char *template);
int mkstemps(char *template, int suffixlen);
int mkstemps64(char *template, int suffixlen);
char *mktemp(char *template);
The mktemp() function returns a unique file name based
on the template parameter. At the time it is generated,
no file in the current directory has that name. No file is actually created,
so it is possible that another application could create a
file with this name.
The mkstemp() function is similar to
mktemp() in that it create a unique file name based
on template; however, mkstemp() actually
creates the file and returns its file descriptor. The name of the created
file is stored in template.
The mkstemp64() function is identical to the
mkstemp() function except that the file is opened with
the O_LARGEFILE flag set.
The mkstemps() function is identical to the
mkstemps() function except that template
can contain a fixed suffix. The length of this suffix is given by the
The mkstemps64() function is identical to the
mkstemps() except that the file is opened with
the O_LARGEFILE flag set.
The mkdtemp() function is similar to
mktemp() except that the name generated is treated
as a directory name which is then created. Like mktemp(),
this function returns the generated name.
The template parameter points to a character buffer
containing a null-terminated string. This string consists of contiguous,
legal file name characters followed by a contiguous string of Xs.
The functions described on this page replace the trailing Xs with
an alphanumeric sequence that is chosen to ensure that no file has that name.
When there is no path information in template, the current
directory is assumed to be where the generated file name will reside.
Xs that appear elsewhere in the string are not replaced.
For the mkstemps() and mkstemps64()
functions, suffixlen characters are ignored when determining
whether the Xs are trailing or not. For example,
ignores the final four characters of the strings (in this case, the
.txt extension) and replaces the three trailing Xs.
When using this functionality to specify file extensions as a part of
the generated name, the period (.) counts as one of the
characters to be ignored. That's why the example above used a
suffixlen of 4 to include the .txt extension.
However, consider this case:
Here, mkstemps() only replaces the X in the
extension when generating a unique file name. The suffixlen of
2 tells it to ignore the xt when looking for trailing
Xs and the period (.) separates the X
in the extension from the others, meaning there is only the one trailing
X to be replaced.
Points to a buffer containing a null-terminated string used as the template
for generating a unique name.
For the mkstemp(), mkstemp64(),
mkstemps(), mkstemps64(), this
buffer is also used to store the resulting unique file name.
Specifies the length of the suffix to be included in the file name generated
by mkstemps() or mkstemps64().
On success, mktemp() and mkdtemp()
return a pointer to the template buffer, which contains
the generated file or directory name. If these functions
cannot generate a unique name, they return a null pointer and
mkdtemp() sets errno to reflect the
error that occurred.
mkstemps(), and mkstemps64()
return a file descriptor to the newly created file and load the
template buffer with the name of this file.
In the event that these functions cannot generate a unique name, they
return -1 and set errno to reflect the error that occurred.
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
- open(), tempnam(), tmpfile(), tmpnam()
PTC MKS Toolkit 10.3 Documentation Build 39.