mktemp() — Make a unique file name

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both POSIX(ON)

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <stdlib.h>

char *mktemp(char *template);

General description

The mktemp() function replaces the contents of the string pointed by template by a unique file name and returns template. The application must initialize template to be a file name with six trailing 'X's; mktemp() replaces each 'X' with a single-byte character from the portable file name character set.

This function is supported only in a POSIX program.

Note: The mktemp() function has been moved to the Legacy Option group in Single UNIX Specification, Version 3 and may be withdrawn in a future version. The mkstemp() function is preferred for portability and greater reliability.

Returned value

If successful, mktemp() returns a pointer to template.

If a unique name cannot be created, mktemp() sets template to a NULL string.

There are no errno values defined.

Related information