NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | ATTRIBUTES | SEE ALSO
#include <stdlib.h>char * mktemp(char * template);
The mktemp function takes the given file name template and overwrites a portion of it to create a file name. This file name is unique and suitable for use by the application. The template may be any file name with a number of X 's appended to it, for example: /tmp/temp.XXXX The trailing X 's are replaced with the current process number and/or a unique letter combination. The number of unique file names mktemp can return depends on the number of X 's provided; six X 's will result in mktemp testing roughly 26 ** 6 combinations.
The mkstemp function makes the same replacement to the template and creates the template file, mode 0600, returning a file descriptor opened for reading and writing. This avoids conflict between testing for a file's existence and opening it for use.
The mktemp function returns a pointer to the template on success and NULL on failure. The mkstemp function returns -1 if no suitable file could be created. If either call fails, the global variable errno is set to indicate one of the following error condiitons.
The mktemp and mkstemp functions will set errno to ENOTDIR if the pathname portion of the template is not an existing directory.
The mktemp and mkstemp functions can also set errno to any value specified by the stat (2POSIX) function.
The mkstemp function can also set errno to any value specified by the open (2POSIX) function.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | ATTRIBUTES | SEE ALSO