Add/fix copyright notices and adjust to latest GNU FDL.
[platform/upstream/coreutils.git] / tests / misc / pwd-long
1 #!/bin/sh
2 # Check "printf" with long arguments.
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 : ${PERL=perl}
22
23 $PERL -e 1 > /dev/null 2>&1 || {
24   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
25     "so can't run this test"
26   exit 77
27 }
28
29 framework_failure=0
30 pwd=`${BUILD_SRC_DIR?}/pwd` || framework_failure=1
31 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
32 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
33 trap '(exit $?); exit $?' 1 2 13 15
34
35 mkdir -p $tmp || framework_failure=1
36 cd $tmp || framework_failure=1
37
38 if test $framework_failure = 1; then
39   echo "$0: failure in testing framework" 1>&2
40   (exit 1); exit 1
41 fi
42
43 ARGV_0=$0
44 export ARGV_0
45
46 CWD=$pwd/$tmp
47 export CWD
48
49 $PERL -w -- - <<\EOF
50
51 # Show that pwd works even when the length of the resulting
52 # directory name is longer than PATH_MAX.
53 use strict;
54 use Cwd;
55
56 (my $ME = $ENV{ARGV_0}) =~ s|.*/||;
57
58 my $cwd = $ENV{CWD};
59 my $z = 'z' x 31;
60 my $n = 256;
61 my $expected = $cwd . ("/$z" x $n);
62
63 my $i = 0;
64 do
65   {
66     mkdir $z, 0700
67       or die "$ME: at depth $i: $!\n";
68     chdir $z;
69   }
70 until (++$i == $n);
71
72 my $build_src_dir = $ENV{BUILD_SRC_DIR};
73 $build_src_dir
74   or die "$ME: envvar BUILD_SRC_DIR not defined\n";
75 my $pwd_binary = "$build_src_dir/pwd";
76 -x $pwd_binary
77   or die "$ME: $pwd_binary is not an executable file\n";
78 chomp (my $actual = `$pwd_binary`);
79 if ($expected ne $actual)
80   {
81     my $e_len = length $expected;
82     my $a_len = length $actual;
83     warn "expected len: $e_len\n";
84     warn "actual len:   $a_len\n";
85     warn "expected: $expected\n";
86     warn "actual: $actual\n";
87     exit 1;
88   }
89 EOF