mktemp(3) — Subroutines
OSF
NAME
mktemp, mkstemp − Constructs a unique filename
LIBRARY
Standard C Library (libc.a),
Berkeley Compatibility Library (libbsd.a)
SYNOPSIS
char ∗mktemp (
char ∗template ); char ∗mkstemp (
char ∗template );
PARAMETERS
templatePoints to a string to be replaced with a unique filename. The string in the template parameter must be a filename with six trailing "X"s.
DESCRIPTION
The mktemp() function replaces the contents of the string pointed to by the template parameter with a unique filename.
NOTES
To get the BSD version of this function, compile with the Berkeley Compatibility Library (libbsd.a).
The mkstemp() function performs the same substitution to the template name and also opens the file for reading and writing.
In BSD systems, the mkstemp() function was intended to avoid a race condition between generating a temporary name and creating the file. Because the name generation in this system is more random, this race condition is less likely.
RETURN VALUES
Upon successful completion, the mktemp() function returns the address of the string pointed to by the template parameter.
If the string pointed to by the template parameter contains no "X"s, or if the mktemp() function is unable to construct a unique filename, the first character of the template parameter string is replaced with a null character, and a null pointer is returned.
Upon successful completion, the mkstemp() function returns an open file descriptor. If the mkstemp() function fails, it returns a value of -1.
RELATED INFORMATION
Functions: tmpfile(3), tmpnam(3), getpid(2)