summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/mktemp.3
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/mktemp.3')
-rw-r--r--lib/libc/stdio/mktemp.3148
1 files changed, 115 insertions, 33 deletions
diff --git a/lib/libc/stdio/mktemp.3 b/lib/libc/stdio/mktemp.3
index 70559fb8185..38ef80008ef 100644
--- a/lib/libc/stdio/mktemp.3
+++ b/lib/libc/stdio/mktemp.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mktemp.3,v 1.51 2013/06/05 03:39:23 tedu Exp $
+.\" $OpenBSD: mktemp.3,v 1.52 2014/08/31 02:21:18 guenther Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,13 +27,15 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: June 5 2013 $
+.Dd $Mdocdate: August 31 2014 $
.Dt MKTEMP 3
.Os
.Sh NAME
.Nm mktemp ,
.Nm mkstemp ,
+.Nm mkostemp ,
.Nm mkstemps ,
+.Nm mkostemps ,
.Nm mkdtemp
.Nd make temporary file name (unique)
.Sh SYNOPSIS
@@ -46,21 +48,34 @@
.Fn mkstemps "char *template" "int suffixlen"
.Ft char *
.Fn mkdtemp "char *template"
+.In stdlib.h
+.In fcntl.h
+.Ft int
+.Fn mkostemp "char *template" "int flags"
+.Ft int
+.Fn mkostemps "char *template" "int suffixlen" "int oflags"
.Sh DESCRIPTION
The
.Fn mktemp
family of functions take the given file name template and overwrite
a portion of it to create a new file name.
This file name is unique and suitable for use by the application.
-The template may be any file name with at least six trailing Xs,
+The template may be any file name with at least six trailing
+.Em X Ns s ,
for example
.Pa /tmp/temp.XXXXXXXX .
-The trailing Xs are replaced with a unique digit and letter combination.
+The trailing
+.Em X Ns s
+are replaced with a unique digit and letter combination.
The number of unique file names that can be returned
-depends on the number of Xs provided;
+depends on the number of
+.Em X Ns s
+provided;
.Fn mktemp
will try at least 2 ** 31 combinations before giving up.
-At least six Xs must be used, though 10 is much better.
+At least six
+.Em X Ns s
+must be used, though 10 is much better.
.Pp
The
.Fn mktemp
@@ -87,14 +102,39 @@ This avoids the race between testing for a file's existence and opening it
for use.
.Pp
The
-.Fn mkstemps
+.Fn mkostemp
function acts the same as
.Fn mkstemp ,
-except it permits a suffix to exist in the template.
+except that the
+.Fa flags
+argument may contain zero or more of the following flags for the underlying
+.Xr open
+system call:
+.Pp
+.Bl -tag -width "O_CLOEXECXX" -offset indent -compact
+.It Dv O_APPEND
+Append on each write.
+.It Dv O_CLOEXEC
+Set the close-on-exec flag on the new file descriptor.
+.It Dv O_SYNC
+Perform synchronous I/O operations.
+.El
+.Pp
+The
+.Fn mkstemps
+and
+.Fn mkostemps
+functions act the same as
+.Fn mkstemp
+and
+.Fn mkostemp ,
+except they permit a suffix to exist in the template.
The template should be of the form
.Pa /tmp/tmpXXXXXXXXXXsuffix .
.Fn mkstemps
-is told the length of the suffix string, i.e.,
+and
+.Fn mkostemps
+are told the length of the suffix string, i.e.,
.Li strlen("suffix") .
.Pp
The
@@ -111,9 +151,11 @@ functions return a pointer to the template on success and
.Dv NULL
on failure.
The
-.Fn mkstemp
+.Fn mkstemp ,
+.Fn mkostemp ,
+.Fn mkstemps ,
and
-.Fn mkstemps
+.Fn mkostemps
functions return \-1 if no suitable file could be created.
If any call fails, an error code is placed in the global variable
.Va errno .
@@ -200,6 +242,7 @@ of
The
.Fn mktemp ,
.Fn mkstemp ,
+.Fn mkostemp ,
and
.Fn mkdtemp
functions may set
@@ -209,44 +252,70 @@ to one of the following values:
.It Bq Er EINVAL
The
.Ar template
-argument has fewer than six trailing Xs.
+argument has fewer than six trailing
+.Em X Ns s .
.It Bq Er EEXIST
All file names tried are already in use.
-Consider appending more Xs to the
+Consider appending more
+.Em X Ns s to the
.Ar template .
.El
.Pp
The
-.Fn mktemp
-function may also set
+.Fn mkstemps
+and
+.Fn mkostemps
+functions may set
.Va errno
-to any value specified by the
-.Xr lstat 2
-function.
+to
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The
+.Ar template
+argument length is less than
+.Ar suffixlen
+or it has fewer than six
+.Em X Ns s
+before the suffix.
+.It Bq Er EEXIST
+All file names tried are already in use.
+Consider appending more
+.Em X Ns s to the
+.Ar template .
+.El
+.Pp
+In addition, the
+.Fn mkostemp
+and
+.Fn mkostemps
+functions may also set
+.Va errno
+to
+.Bl -tag -width Er
+.It Bq Er EINVAL
+.Fa flags
+is invalid.
+.El
.Pp
The
-.Fn mkstemp
+.Fn mktemp
function may also set
.Va errno
to any value specified by the
-.Xr open 2
+.Xr lstat 2
function.
.Pp
The
-.Fn mkstemps
-function may also set
+.Fn mkstemp ,
+.Fn mkostemp ,
+.Fn mkstemps ,
+and
+.Fn mkostemps
+functions may also set
.Va errno
to any value specified by the
.Xr open 2
-function or,
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The
-.Ar template
-argument length is less than
-.Ar suffixlen
-or it has fewer than six Xs before the suffix.
-.El
+function.
.Pp
The
.Fn mkdtemp
@@ -271,7 +340,12 @@ and
functions conform to the
.St -p1003.1-2008
specification.
-The ability to specify more than six Xs is an extension to that standard.
+The ability to specify more than six
+.Em X Ns s
+is an extension to that standard.
+The
+.Fn mkostemp
+function is expected to conform to a future revision of that standard.
.Pp
The
.Fn mktemp
@@ -283,7 +357,9 @@ it is no longer a part of the standard.
.Pp
The
.Fn mkstemps
-function is non-standard and should not be used if portability is required.
+and
+.Fn mkostemps
+functions are non-standard and should not be used if portability is required.
.Sh HISTORY
A
.Fn mktemp
@@ -301,6 +377,12 @@ The
.Fn mkstemps
function appeared in
.Ox 2.3 .
+The
+.Fn mkostemp
+and
+.Fn mkostemps
+functions appeared in
+.Ox 5.7 .
.Sh BUGS
For
.Fn mktemp