Add/fix copyright notices and adjust to latest GNU FDL.
[platform/upstream/coreutils.git] / tests / ls / stat-dtype
1 #!/bin/sh
2 # Ensure that ls --file-type does not call stat unnecessarily.
3
4 # Copyright (C) 2006 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 # The trick is to create an un-stat'able symlink and to see if ls
22 # can report its type nonetheless, using dirent.d_type.
23
24 if test "$VERBOSE" = yes; then
25   set -x
26   ls --version
27 fi
28
29 . $srcdir/../envvar-check
30
31 # Skip this test unless "." is on a file system with useful d_type info.
32 # FIXME: use a more dynamic test for this, since whether d_type is useful
33 # depends on much more than the file system type.  For example, with
34 # linux-2.6.15, at least tmpfs and ext3 work, but reiserfs and xfs don't.
35 # Also, tmpfs on Solaris 10 lacks d_type support.
36 skip=yes
37 fs_type=`stat -f --printf %T .`
38 test `uname -s` = Linux && test $fs_type = tmpfs && skip=no
39 test $fs_type = ext2/ext3 && skip=no
40 test $skip = yes &&
41   {
42     echo "$0: '.' is not on a suitable file system for this test" 1>&2
43     echo "$0: skipping this test" 1>&2
44     (exit 77); exit 77
45   }
46
47 pwd=`pwd`
48 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
49 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
50 trap '(exit $?); exit $?' 1 2 13 15
51
52 framework_failure=0
53 mkdir -p $tmp || framework_failure=1
54 cd $tmp || framework_failure=1
55
56 mkdir d || framework_failure=1
57 ln -s / d/s || framework_failure=1
58 chmod 600 d || framework_failure=1
59
60 if test $framework_failure = 1; then
61   echo "$0: failure in testing framework" 1>&2
62   (exit 1); exit 1
63 fi
64
65 fail=0
66
67 ls --file-type d > out || fail=1
68 cat <<\EOF > exp || fail=1
69 s@
70 EOF
71
72 cmp out exp || fail=1
73 test $fail = 1 && diff out exp 2> /dev/null
74
75 (exit $fail); exit $fail