.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\" SUCH DAMAGE.
.\"
.\" From: $OpenBSD: mktemp.1,v 1.8 1998/03/19 06:13:37 millert Exp $
-.\" $FreeBSD: src/usr.bin/mktemp/mktemp.1,v 1.7.2.6 2001/07/22 12:40:27 dd Exp $
+.\" $FreeBSD$
.\"
-.Dd November 20, 1996
+.Dd December 30, 2005
.Dt MKTEMP 1
.Os
.Sh NAME
The
.Nm
utility takes each of the given file name templates and overwrites a
-portion of it to create a file name. This file name is unique
-and suitable for use by the application. The template may be
+portion of it to create a file name.
+This file name is unique
+and suitable for use by the application.
+The template may be
any file name with some number of
.Ql X Ns s
appended
will
result in
.Nm
-testing roughly 26 ** 6 combinations.
+selecting 1 of 56800235584 (62 ** 6) possible file names.
+On case-insensitive file systems, the effective number of unique
+names is significantly less; given six
+.Ql X Ns s ,
+.Nm
+will instead select 1 of 2176782336 (36 ** 6) possible unique file names.
.Pp
If
.Nm
.Fl t Ar prefix
option is given,
.Nm
-will generate an template string based on the
+will generate a template string based on the
.Ar prefix
and the
+.Dv _CS_DARWIN_USER_TEMP_DIR
+configuration variable if available.
+Fallback locations if
+.Dv _CS_DARWIN_USER_TEMP_DIR
+is not available are
.Ev TMPDIR
-environment variable if set.
-The default location if
-.Ev TMPDIR
-is not set is
+and
.Pa /tmp .
Care should
be taken to ensure that it is appropriate to use an environment variable
potentially supplied by the user.
.Pp
+If no arguments are passed or if only the
+.Fl d
+flag is passed
+.Nm
+behaves as if
+.Fl t Li tmp
+was supplied.
+.Pp
Any number of temporary files may be created in a single invocation,
including one based on the internal template resulting from the
.Fl t
flag.
.Pp
-.Nm Mktemp
-is provided to allow shell scripts to safely use temporary files.
+The
+.Nm
+utility is provided to allow shell scripts to safely use temporary files.
Traditionally, many shell scripts take the name of the program with
-the pid as a suffix and use that as a temporary file name. This
+the pid as a suffix and use that as a temporary file name.
+This
kind of naming scheme is predictable and the race condition it creates
-is easy for an attacker to win. A safer, though still inferior, approach
-is to make a temporary directory using the same naming scheme. While
+is easy for an attacker to win.
+A safer, though still inferior, approach
+is to make a temporary directory using the same naming scheme.
+While
this does allow one to guarantee that a temporary file will not be
-subverted, it still allows a simple denial of service attack. For these
+subverted, it still allows a simple denial of service attack.
+For these
reasons it is suggested that
.Nm
be used instead.
.It Fl d
Make a directory instead of a file.
.It Fl q
-Fail silently if an error occurs. This is useful if
+Fail silently if an error occurs.
+This is useful if
a script does not want error output to go to standard error.
.It Fl t Ar prefix
Generate a template (using the supplied
.It Fl u
Operate in
.Dq unsafe
-mode. The temp file will be unlinked before
+mode.
+The temp file will be unlinked before
.Nm
-exits. This is slightly better than
+exits.
+This is slightly better than
.Xr mktemp 3
-but still introduces a race condition. Use of this
+but still introduces a race condition.
+Use of this
option is not encouraged.
.El
-.Sh DIAGNOSTICS
-The
-.Nm
-utility
-exits 0 on success, and 1 if an error occurs.
+.Sh EXIT STATUS
+.Ex -std
.Sh EXAMPLES
The following
.Xr sh 1
.Xr mkdtemp 3 ,
.Xr mkstemp 3 ,
.Xr mktemp 3 ,
+.Xr confstr 3 ,
.Xr environ 7
.Sh HISTORY
A
first appeared in
.Fx 2.2.7 .
This man page is taken from
-.Ox
+.Ox .