MKTEMP(3)

NAME
4.41 `mktemp', `mkstemp', `mkstemps'--generate unused file name

SYNOPSIS
     #include <stdlib.h>
     char *mktemp(char *PATH);
     char *mkdtemp(char *PATH);
     int mkstemp(char *PATH);
     int mkstemps(char *PATH, int SUFFIXLEN);
     char *_mktemp_r(struct _reent *REENT, char *PATH);
     char *_mkdtemp_r(struct _reent *REENT, char *PATH);
     int *_mkstemp_r(struct _reent *REENT, char *PATH);
     int *_mkstemps_r(struct _reent *REENT, char *PATH, int LEN);

DESCRIPTION
`mktemp', `mkstemp', and `mkstemps' attempt to generate a file name that is not yet in use for any existing file. `mkstemp' and `mkstemps' create the file and open it for reading and writing; `mktemp' simply generates the file name (making `mktemp' a security risk). `mkdtemp' attempts to create a directory instead of a file, with a permissions mask of 0700.
   You supply a simple pattern for the generated file name, as the string at PATH. The pattern should be a valid filename (including path information if you wish) ending with at least six ``X'' characters. The generated filename will match the leading part of the name you supply, with the trailing ``X'' characters replaced by some combination of digits and letters. With `mkstemps', the ``X'' characters end SUFFIXLEN bytes before the end of the string.
   The alternate functions `_mktemp_r', `_mkdtemp_r', `_mkstemp_r', and `_mkstemps_r' are reentrant versions. The extra argument REENT is a pointer to a reentrancy structure.

RETURNS
`mktemp' returns the pointer PATH to the modified string representing an unused filename, unless it could not generate one, or the pattern you provided is not suitable for a filename; in that case, it returns `NULL'.
   `mkdtemp' returns the pointer PATH to the modified string if the directory was created, otherwise it returns `NULL'.
   `mkstemp' and `mkstemps' return a file descriptor to the newly created file, unless it could not generate an unused filename, or the pattern you provided is not suitable for a filename; in that case, it returns `-1'.

PORTABILITY
ANSI C does not require either `mktemp' or `mkstemp'; the System V Interface Definition requires `mktemp' as of Issue 2. POSIX 2001 requires `mkstemp', and POSIX 2008 requires `mkdtemp', but `mkstemps' is not standardized.
   Supporting OS subroutines required: `getpid', `mkdir', `open', `stat'.

SEE ALSO
mktemp is part of the library. The full documentation for is maintained as a Texinfo manual. If info and are properly installed at your site, the command

    info

will give you access to the complete manual.