HP-UX Reference (11i v1 00/12) - 3 Library Functions A-M (vol 6)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/!!!intro.3c
________________________________________________________________
___ ___
m
mktemp(3C) mktemp(3C)
NAME
mktemp(), mkstemp() - make a unique file name
SYNOPSIS
#include <stdlib.h>
char *mktemp(char *template);
int mkstemp(char *template);
Remarks:
These functions are provided solely for backward compatibility and importability of applications, and
are not recommended for new applications where portability is important. For portable applications,
use tmpfile() instead (see tmpfile(3S)).
DESCRIPTION
mktemp() replaces the contents of the string pointed to by template by a unique file name, and returns
the address of template. The string in template should look like a file name with six trailing Xs;
mktemp() replaces the Xs with a letter and the current process
ID. The letter is chosen such that the
resulting name does not duplicate the name of an existing file. If there are fewer than six
Xs, the letter is
dropped first, followed by dropping the high-order digits of the process
ID.
mkstemp() makes the same replacement to the template, but also returns a file descriptor for the tem-
plate file after opening the file for reading and writing. mkstemp() thus prevents any possible race con-
dition between testing whether the file exists and opening it for use.
APPLICATION USAGE
mktemp() and mkstemp() are thread-safe. mktemp() is async-cancel-safe.
mkstemp() is not
async-cancel-safe. A cancellation point may occur when a thread is executing
mkstemp().
RETURN VALUE
mktemp() returns its argument except when it runs out of letters, in which case the result is a pointer to
the empty string "".
mkstemp() returns an open file descriptor upon successful completion, or -1 if no suitable file could be
created.
WARNINGS
It is possible to run out of letters.
mktemp() and mkstemp() do not check to determine whether the file name part of template exceeds
the maximum allowable file name length.
SEE ALSO
getpid(2), open(2), tmpfile(3S), tmpnam(3S).
STANDARDS CONFORMANCE
mktemp(): SVID2, SVID3, XPG2
HP-UX Release 11i: December 2000 1 Section 3523
___
___