tests: misc/printf: accommodate alternate behavior
[platform/upstream/coreutils.git] / tests / other-fs-tmpdir
1 #! /bin/sh
2
3 # Use stat to find a writable directory on a file system different from that
4 # of the current directory.  If one is found, create a temporary directory
5 # inside it.
6
7 # Copyright (C) 1998-1999, 2001-2002, 2005, 2007-2011 Free Software Foundation,
8 # Inc.
9
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 test "${CANDIDATE_TMP_DIRS+set}" = set \
24   || CANDIDATE_TMP_DIRS="$TMPDIR /tmp /dev/shm /var/tmp /usr/tmp $HOME"
25
26 other_partition_tmpdir=
27
28 dot_mount_point=`stat -c %d .`
29 for d in $CANDIDATE_TMP_DIRS; do
30
31   # Skip nonexistent directories.
32   test -d "$d" || continue
33
34   d_mount_point=`stat -L -c %d "$d"`
35
36   # Same partition?  Skip it.
37   test "x$d_mount_point" = "x$dot_mount_point" && continue
38
39   # See if we can create a directory in it.
40   if mkdir "$d/tmp$$" > /dev/null 2>&1; then
41     other_partition_tmpdir="$d/tmp$$"
42     break
43   fi
44
45 done
46
47 if test -z "$other_partition_tmpdir"; then
48   skip_ \
49 "requires a writable directory on a different disk partition,
50 and I couldn't find one.  I tried these:
51   $CANDIDATE_TMP_DIRS
52 Set your environment variable CANDIDATE_TMP_DIRS to make
53 this test use a different list."
54 fi
55
56 test "$VERBOSE" = yes && set -x