document that created file is 0600
[unix-history] / usr / src / lib / libc / stdio / mktemp.3
.\" @(#)mktemp.3 6.4 (Berkeley) %G%
.\"
.TH MKTEMP 3 ""
.AT 3
.SH NAME
mktemp \- make a unique file name
.SH SYNOPSIS
.nf
.B char *mktemp(template)
.B char *template;
.sp
.B mkstemp(template)
.B char *template;
.fi
.SH DESCRIPTION
\fIMktemp\fP creates a unique file name and returns the address of
the template. The template should contain a file name with trailing
\fIX\fP's, normally something like \fI/tmp/tempXXXXXX\fP. The \fIX\fP's
are replaced by the current process number and/or a unique letter
combination. \fIMkstemp\fP makes the same replacement to the template
but creates the template file, mode 0600, and returns a file descriptor
open for reading and writing. \fIMkstemp\fP avoids the race between testing
whether the file exists and opening it for use. The number of file
name combinations \fImktemp\fP and \fImkstemp\fP will try depends on
the number of \fIX\fP's placed on the end of the template; six \fIX\fP's
will result in them trying roughly 26 ** 6 combinations.
.SH "SEE ALSO"
chmod(2), getpid(2), open(2), stat(2)
.SH DIAGNOSTICS
\fIMktemp\fP returns NULL on failure, \fImkstemp\fP returns -1 if no
suitable file could be created.