[BACK]Return to mktemp.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / mktemp

Annotation of src/usr.bin/mktemp/mktemp.1, Revision 1.6

1.6     ! millert     1: .\"    $OpenBSD: mktemp.1,v 1.5 1997/06/17 15:34:27 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: .\"
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.
1.6     ! millert    96: .El
1.1       millert    97: .Sh RETURN VALUES
                     98: The
                     99: .Nm
                    100: utility
                    101: exits with a value of 0 on success, and 1 on failure.
                    102: .Sh EXAMPLES
                    103: The following
                    104: .Xr sh 1
                    105: fragment illustrates a simple use of
                    106: .Nm
                    107: where the script should quit if it cannot get a safe
                    108: temporary file.
                    109: .Bd -literal -offset indent
                    110: TMPFILE=`mktemp /tmp/$0.XXXXXX` || exit 1
                    111: echo "program output" >> $TMPFILE
                    112: .Ed
                    113: .Pp
                    114: In this case, we want the script to catch the error itself.
                    115: .Bd -literal -offset indent
1.3       millert   116: TMPFILE=`mktemp -q /tmp/$0.XXXXXX`
1.2       millert   117: if [ $? -ne 0 ]; then
1.1       millert   118:        echo "$0: Can't create temp file, exiting..."
                    119:        exit 1
                    120: fi
                    121: .Ed
                    122: .Pp
                    123: Note that one can also check to see that $TMPFILE is
                    124: zero length instead of checking $?.  This would allow
                    125: the check to be done later one in the script (since
                    126: $? would get clobbered by the next shell command).
                    127: .Sh SEE ALSO
                    128: .Xr mkstemp 3 ,
                    129: .Xr mktemp 3
                    130: .Sh HISTORY
                    131: The
                    132: .Nm
                    133: utility appeared in
                    134: .Bx Open .