Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 68 lines (58 sloc) 2.217 kb
23a2e66 @LupeChristoph Updated to final 1.2.4 version [merged change r98r984 from /branches…
LupeChristoph authored
1 #!/bin/sh
2
3 # This file tries to determine the best method to create a tempfile
4 # by testing various methods.
5
6 # Copyright (c) 2005, Lutz Peter Christoph
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 #
16 # * Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in
18 # the documentation and/or other materials provided with the
19 # distribution.
20 #
21 # * The name and aliases of Lutz Peter Christoph ("Lupe Christoph",
22 # "Lutz Christoph") may not be used to endorse or promote products
23 # derived from this software without specific prior written
24 # permission.
25 #
26 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
38
39 testfun () {
40 TEMP_FILE=`eval $MKTEMP 2>/dev/null`
41 STATUS=$?
42 if [ $STATUS = 0 -a -n "$TEMP_FILE" -a -f "$TEMP_FILE" ]; then
43 rm -f $TEMP_FILE
44 echo $MKTEMP
45 exit
46 else
47 rm -f $TEMP_FILE
48 fi
49 }
50
51 # Preferred
52 MKTEMP='mktemp -p /tmp/ $1'
53 testfun temp.XXXXXX
54
55 # FreeBSD way
56 MKTEMP="mktemp -t /tmp"
57 testfun temp.XXXXXX
58
59 # Plain mktemp
60 MKTEMP="mktemp /tmp/$1"
61 testfun temp.XXXXXX
62
63 # No mktemp at all
64 MKTEMP='rm -rf /tmp/$1.$$ && touch /tmp/$1.$$ && chmod 600 /tmp/$1.$$ && echo /tmp/$1.$$'
65 testfun temp.XXXXXX
66
67 exit 1
Something went wrong with that request. Please try again.