xref: /freebsd/bin/sh/tests/builtins/cd4.0 (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1
2# This test assumes that whatever mechanism cd -P uses to determine the
3# pathname to the current directory if it is longer than PATH_MAX requires
4# read permission on all parent directories. It also works if this
5# requirement always applies.
6
7set -e
8L=$(getconf PATH_MAX / 2>/dev/null) || L=4096
9[ "$L" -lt 100000 ] 2>/dev/null || L=4096
10L=$((L+100))
11T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
12trap 'chmod u+r ${T}; rm -rf ${T}' 0
13cd -Pe $T
14D=$(pwd)
15chmod u-r "$D"
16if [ -r "$D" ]; then
17	# Running as root, cannot test.
18	exit 0
19fi
20set +e
21while [ ${#D} -lt $L ]; do
22	mkdir veryverylongdirectoryname || exit
23	cd -Pe veryverylongdirectoryname 2>/dev/null
24	r=$?
25	[ $r -gt 1 ] && exit $r
26	if [ $r -eq 1 ]; then
27		# Verify that the directory was changed correctly.
28		cd -Pe .. || exit
29		[ "$(pwd)" = "$D" ] || exit
30		# Verify that omitting -e results in success.
31		cd -P veryverylongdirectoryname 2>/dev/null || exit
32		exit 0
33	fi
34	D=$D/veryverylongdirectoryname
35done
36echo "cd -Pe never returned 1"
37exit 0
38