Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

OSS Library Calls (i - m) mkstemp(3)
NAME
mkstemp, mktemp - Makes a unique filename
LIBRARY
G-series native OSS processes: /G/system/sysnn/zosshsrl
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zosshdll |
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/yosshdll |
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 filenames.
DESCRIPTION
The mkstemp( ) function uses the contents of the string pointed to by the template parameter to
create a unique filename, which replaces the strings contents. It returns a file descriptor for this
file that is open for reading and writing. There is no gap in time between determining that the file
does not exist and opening it, thus preventing another process from creating a file with the same
name.
The mktemp() function uses the contents of the string pointed to by the template parameter to
create a unique filename, 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
filename with six trailing X characters. Each X character is replaced with a single byte character
from the portable filename character set, selecting characters such that the resulting filename has
the the current process ID encoded within it and does not duplicate any existing filename.
NOTES
The mkstemp( ) and mktemp( ) functions can be called by native processes only.
CAUTIONS
Because the mktemp( ) function only generates a filename and does not open it, it is possible for
another process to create a file 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 filenames.
RETURN VALUES
On successful completion, the mkstemp( ) function returns an open file descriptor. Otherwise, it
returns -1 if no suitable file could be created.
The mktemp() function returns the pointer template. If it cannot create a unique filename, tem-
plate points to a null string.
ERRORS
None. These functions do not set errno.
RELATED INFORMATION
Functions: getpid(2), open(2).
527187-017 Hewlett-Packard Company 4203