Annotation of src/usr.bin/mktemp/mktemp.1, Revision 1.2
1.2 ! millert 1: .\" $OpenBSD: mktemp.1,v 1.1 1996/11/21 07:59:32 millert 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: .\"
34: .Dd "November 20, 1996"
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
42: .Op Fl u
43: .Op Fl q
44: .Ar template
45: .Sh DESCRIPTION
46: The
47: .Nm mktemp
48: utility takes the given file name template and overwrites a
49: portion of it to create a file name. This file name is unique
50: and suitable for use by the application. The template may be
51: any file name with some number of
52: .Ql X Ns s
53: appended
54: to it, for example
55: .Pa /tmp/temp.XXXX .
56: The trailing
57: .Ql X Ns s
58: are replaced with the current process number and/or a
59: unique letter combination.
60: The number of unique file names
61: .Nm
62: can return depends on the number of
63: .Ql X Ns s
64: provided; six
65: .Ql X Ns s
66: will
67: result in
68: .Nm
69: testing roughly 26 ** 6 combinations.
70: .Pp
71: If
72: .Nm
73: can successfully generate a unique file name, the file
74: is created with mode 0600 (unless the
75: .Fl u
76: flag is given) and the filename is printed
77: to standard output.
78: .Sh OPTIONS
79: .Bl -tag -width indent
80: The available options are as follows:
81: .It Fl u
82: Operate in
83: .Dq unsafe
84: mode. The temp file will be unlinked before
85: .Nm
86: exits. This is slightly better than
87: .Fn mktemp 3
88: but still introduces a race condition. Use of this
89: option is not encouraged.
90: .It Fl q
91: Fail silently if an error occurs. This is useful if
92: a script does not want error output to go to standard error.
93: .Sh RETURN VALUES
94: The
95: .Nm
96: utility
97: exits with a value of 0 on success, and 1 on failure.
98: .Sh EXAMPLES
99: The following
100: .Xr sh 1
101: fragment illustrates a simple use of
102: .Nm
103: where the script should quit if it cannot get a safe
104: temporary file.
105: .Bd -literal -offset indent
106: TMPFILE=`mktemp /tmp/$0.XXXXXX` || exit 1
107: echo "program output" >> $TMPFILE
108: .Ed
109: .Pp
110: In this case, we want the script to catch the error itself.
111: .Bd -literal -offset indent
112: TMPFILE=`mktemp -s /tmp/$0.XXXXXX`
1.2 ! millert 113: if [ $? -ne 0 ]; then
1.1 millert 114: echo "$0: Can't create temp file, exiting..."
115: exit 1
116: fi
117: .Ed
118: .Pp
119: Note that one can also check to see that $TMPFILE is
120: zero length instead of checking $?. This would allow
121: the check to be done later one in the script (since
122: $? would get clobbered by the next shell command).
123: .Sh SEE ALSO
124: .Xr mkstemp 3 ,
125: .Xr mktemp 3
126: .Sh HISTORY
127: The
128: .Nm
129: utility appeared in
130: .Bx Open .