Annotation of src/usr.bin/mktemp/mktemp.1, Revision 1.5
1.5 ! millert 1: .\" $OpenBSD: mktemp.1,v 1.4 1997/05/30 07:49:25 deraadt Exp $
1.1 millert 2: .\"
3: .\" Copyright (c) 1989, 1991, 1993
4: .\" The Regents of the University of California. All rights reserved.
5: .\"
6: .\" Redistribution and use in source and binary forms, with or without
7: .\" modification, are permitted provided that the following conditions
8: .\" are met:
9: .\" 1. Redistributions of source code must retain the above copyright
10: .\" notice, this list of conditions and the following disclaimer.
11: .\" 2. Redistributions in binary form must reproduce the above copyright
12: .\" notice, this list of conditions and the following disclaimer in the
13: .\" documentation and/or other materials provided with the distribution.
14: .\" 3. All advertising materials mentioning features or use of this software
15: .\" must display the following acknowledgement:
16: .\" This product includes software developed by the University of
17: .\" California, Berkeley and its contributors.
18: .\" 4. Neither the name of the University nor the names of its contributors
19: .\" may be used to endorse or promote products derived from this software
20: .\" without specific prior written permission.
21: .\"
22: .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25: .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32: .\" SUCH DAMAGE.
33: .\"
1.4 deraadt 34: .Dd November, 20, 1996
1.1 millert 35: .Dt MKTEMP 1
36: .Os
37: .Sh NAME
38: .Nm mktemp
39: .Nd make temporary file name (unique)
40: .Sh SYNOPSIS
41: .Nm mktemp
1.5 ! millert 42: .Op Fl d
! 43: .Op Fl q
1.1 millert 44: .Op Fl u
45: .Ar template
46: .Sh DESCRIPTION
47: The
48: .Nm mktemp
49: utility takes the given file name template and overwrites a
50: portion of it to create a file name. This file name is unique
51: and suitable for use by the application. The template may be
52: any file name with some number of
53: .Ql X Ns s
54: appended
55: to it, for example
56: .Pa /tmp/temp.XXXX .
57: The trailing
58: .Ql X Ns s
59: are replaced with the current process number and/or a
60: unique letter combination.
61: The number of unique file names
62: .Nm
63: can return depends on the number of
64: .Ql X Ns s
65: provided; six
66: .Ql X Ns s
67: will
68: result in
69: .Nm
70: testing roughly 26 ** 6 combinations.
71: .Pp
72: If
73: .Nm
74: can successfully generate a unique file name, the file
75: is created with mode 0600 (unless the
76: .Fl u
77: flag is given) and the filename is printed
78: to standard output.
79: .Sh OPTIONS
80: .Bl -tag -width indent
81: The available options are as follows:
1.5 ! millert 82: .It Fl d
! 83: Make a directory instead of a file.
! 84: .It Fl q
! 85: Fail silently if an error occurs. This is useful if
! 86: a script does not want error output to go to standard error.
1.1 millert 87: .It Fl u
88: Operate in
89: .Dq unsafe
90: mode. The temp file will be unlinked before
91: .Nm
92: exits. This is slightly better than
93: .Fn mktemp 3
94: but still introduces a race condition. Use of this
95: option is not encouraged.
96: .Sh RETURN VALUES
97: The
98: .Nm
99: utility
100: exits with a value of 0 on success, and 1 on failure.
101: .Sh EXAMPLES
102: The following
103: .Xr sh 1
104: fragment illustrates a simple use of
105: .Nm
106: where the script should quit if it cannot get a safe
107: temporary file.
108: .Bd -literal -offset indent
109: TMPFILE=`mktemp /tmp/$0.XXXXXX` || exit 1
110: echo "program output" >> $TMPFILE
111: .Ed
112: .Pp
113: In this case, we want the script to catch the error itself.
114: .Bd -literal -offset indent
1.3 millert 115: TMPFILE=`mktemp -q /tmp/$0.XXXXXX`
1.2 millert 116: if [ $? -ne 0 ]; then
1.1 millert 117: echo "$0: Can't create temp file, exiting..."
118: exit 1
119: fi
120: .Ed
121: .Pp
122: Note that one can also check to see that $TMPFILE is
123: zero length instead of checking $?. This would allow
124: the check to be done later one in the script (since
125: $? would get clobbered by the next shell command).
126: .Sh SEE ALSO
127: .Xr mkstemp 3 ,
128: .Xr mktemp 3
129: .Sh HISTORY
130: The
131: .Nm
132: utility appeared in
133: .Bx Open .