2
# Show that --color need not use stat, as long as we have d_type support.
4
# Copyright (C) 2011 Free Software Foundation, Inc.
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 3 of the License, or
9
# (at your option) any later version.
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.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
. "${srcdir=.}/init.sh"; path_prepend_ ../src
22
require_dirent_d_type_
25
ln -s nowhere dangle-$i || framework_failure_
28
# Disable enough features via LS_COLORS so that ls --color
29
# can do its job without calling stat (other than the obligatory
30
# one-call-per-command-line argument).
31
cat <<EOF > color-without-stat || framework_failure_
44
STICKY_OTHER_WRITABLE 00
50
eval $(dircolors -b color-without-stat)
52
# The system may perform additional stat-like calls before main.
53
# To avoid counting those, first get a baseline count by running
54
# ls with only the --help option. Then, compare that with the
55
# invocation under test.
56
strace -o log-help -e stat,lstat,stat64,lstat64 ls --help >/dev/null || fail=1
57
n_lines_help=$(wc -l < log-help)
59
strace -o log -e stat,lstat,stat64,lstat64 ls --color=always . || fail=1
60
n_lines=$(wc -l < log)
62
n_stat=$(expr $n_lines - $n_lines_help)
64
# Expect one or two stat calls.
67
*) fail=1; head -n30 log* ;;