Open System Services Library Calls Reference Manual (G06.28+, H06.05+)

mkstemp(3) OSS Library Calls Reference Manual
NAME
mkstemp, mktemp - Makes a unique lename
LIBRARY
G-series native OSS processes: /G/system/sysnn/zosshsrl
H-series OSS processes: /G/system/zdllnnn/zosshdll
SYNOPSIS
#include <stdlib.h>
int mkstemp(char *template);
char *mktemp(char *template);
PARAMETERS
template Is a pointer to a string that serves as the template for creating unique lenames.
DESCRIPTION
The mkstemp() function uses the contents of the string pointed to by the template parameter to
create a unique lename, which replaces the strings contents. It returns a le descriptor for this
le that is open for reading and writing. There is no gap in time between determining that the le
does not exist and opening it, thus preventing another process from creating a le with the same
name.
The mktemp() function uses the contents of the string pointed to by the template parameter to
create a unique lename, which replaces the strings contents. It returns template.
For both of these functions, the template parameter must point to a string that looks like a
lename with six trailing X characters. Each X character is replaced with a single byte character
from the portable lename character set, selecting characters such that the resulting lename has
the the current process ID encoded within it and does not duplicate any existing lename.
NOTES
The mkstemp() and mktemp() functions can be called by native processes only.
CAUTIONS
Because the mktemp() function only generates a lename and does not open it, it is possible for
another process to create a le with the same name before you can open it. The mkstemp()
function avoids this problem.
It is possible to run out of letters to append for lenames.
RETURN VALUES
On successful completion, the mkstemp() function returns an open le descriptor. Otherwise, it
returns -1 if no suitable le could be created.
The mktemp() function returns the pointer template. If it cannot create a unique lename, tem-
plate points to a null string.
ERRORS
None. These functions do not set errno.
RELATED INFORMATION
Functions: getpid(2), open(2).
4132 Hewlett-Packard Company 527187-007