.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
.\" and Copyright (C) 2008, Michael Kerrisk <mtk.manpages@gmail.com>
.\"
+.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
.\"
.\" References consulted:
.\" Linux libc source code
.\" Modified 990328, aeb
.\" 2008-06-19, mtk, Added mkostemp(); various other changes
.\"
-.TH MKSTEMP 3 2010-09-26 "GNU" "Linux Programmer's Manual"
+.TH MKSTEMP 3 2014-08-19 "GNU" "Linux Programmer's Manual"
.SH NAME
-mkstemp, mkostemp \- create a unique temporary file
+mkstemp, mkostemp, mkstemps, mkostemps \- create a unique temporary file
.SH SYNOPSIS
.nf
.B #include <stdlib.h>
.sp
.BI "int mkstemp(char *" template );
.sp
-.BI "int mkostemp (char *" template ", int " flags );
+.BI "int mkostemp(char *" template ", int " flags );
.sp
.BI "int mkstemps(char *" template ", int " suffixlen );
.sp
The file is created with
permissions 0600, that is, read plus write for owner only.
-(In glibc versions 2.06 and earlier, the file is created with permissions 0666,
-that is, read and write for all users.)
The returned file descriptor provides both read and write access to the file.
The file is opened with the
.BR open (2)
.BR mkostemp ()
function is like
.BR mkstemp (),
-with the difference that flags as for
-.BR open (2)
-may be specified in
-.IR flags
-(e.g.,
+with the difference that the following bits\(emwith the same meaning as for
+.BR open (2)\(emmay
+be specified in
+.IR flags :
.BR O_APPEND ,
-.BR O_SYNC ).
+.BR O_CLOEXEC ,
+and
+.BR O_SYNC .
+Note that when creating the file,
+.BR mkostemp ()
+includes the values
+.BR O_RDWR ,
+.BR O_CREAT ,
+and
+.BR O_EXCL
+in the
+.I flags
+argument given to
+.BR open (2);
+including these values in the
+.I flags
+argument given to
+.BR mkostemp ()
+is unnecessary, and produces errors on some
+.\" Reportedly, FreeBSD
+systems.
The
.BR mkstemps ()
.BR mkostemp ()
is to
.BR mkstemp ().
-.SH "RETURN VALUE"
+.SH RETURN VALUE
On success, these functions return the file descriptor
of the temporary file.
On error, \-1 is returned, and
For
.BR mkstemps ()
and
-.BR mkostemps ()
+.BR mkostemps ():
.I template
is less than
.I "(6 + suffixlen)"
and
.BR mkostemps ()
are available since glibc 2.11.
-.SH "CONFORMING TO"
+.SH ATTRIBUTES
+.SS Multithreading (see pthreads(7))
+The
+.BR mkstemp (),
+.BR mkostemp (),
+.BR mkstemps (),
+and
+.BR mkostemps ()
+functions are thread-safe.
+.SH CONFORMING TO
.BR mkstemp ():
4.3BSD, POSIX.1-2001.
.BR mkostemps ():
are glibc extensions.
.SH NOTES
-The old behavior of creating a file with mode 0666 may be
+In glibc versions 2.06 and earlier, the file is created with permissions 0666,
+that is, read and write for all users.
+This old behavior may be
a security risk, especially since other UNIX flavors use 0600,
and somebody might overlook this detail when porting programs.
+POSIX.1-2008 adds a requirement that the file be created with mode 0600.
More generally, the POSIX specification of
.BR mkstemp ()
.BR mkstemp ()
(and
.BR mkostemp ()).
-
-The prototype for
-.BR mktemp ()
-is in
-.I <unistd.h>
-for libc4, libc5, glibc1; glibc2 follows POSIX.1 and has the prototype in
-.IR <stdlib.h> .
-.SH "SEE ALSO"
+.\"
+.\" The prototype for
+.\" .BR mktemp ()
+.\" is in
+.\" .I <unistd.h>
+.\" for libc4, libc5, glibc1; glibc2 follows POSIX.1 and has the prototype in
+.\" .IR <stdlib.h> .
+.SH SEE ALSO
.BR mkdtemp (3),
.BR mktemp (3),
.BR tempnam (3),
.BR tmpfile (3),
.BR tmpnam (3)
+.SH COLOPHON
+This page is part of release 3.79 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.