diff options
Diffstat (limited to 'posix')
-rw-r--r-- | posix/globtest.c | 19 | ||||
-rwxr-xr-x | posix/globtest.sh | 76 |
2 files changed, 87 insertions, 8 deletions
diff --git a/posix/globtest.c b/posix/globtest.c index 970d90a31c..90b9eb6ad3 100644 --- a/posix/globtest.c +++ b/posix/globtest.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 1998 Free Software Foundation, Inc. +/* Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -29,7 +29,9 @@ main (int argc, char *argv[]) glob_t g; int quotes = 1; - while ((i = getopt (argc, argv, "bcdegmopqstT")) != -1) + g.gl_offs = 0; + + while ((i = getopt (argc, argv, "bcdeEgmopqstT")) != -1) switch(i) { case 'b': @@ -44,6 +46,9 @@ main (int argc, char *argv[]) case 'e': glob_flags |= GLOB_NOESCAPE; break; + case 'E': + glob_flags |= GLOB_ERR; + break; case 'g': glob_flags |= GLOB_NOMAGIC; break; @@ -96,15 +101,17 @@ main (int argc, char *argv[]) else if (i == GLOB_NOMATCH) puts ("GLOB_NOMATCH"); - /* If we set an offset, fill in the first field. */ - if (glob_flags & GLOB_DOOFFS) + /* If we set an offset, fill in the first field. + (Unless glob() has filled it in already - which is an error) */ + if ((glob_flags & GLOB_DOOFFS) && g.gl_pathv[0] == NULL) g.gl_pathv[0] = (char *) "abc"; /* Print out the names. Unless otherwise specified, qoute them. */ if (g.gl_pathv) { - for (i = 0; i < g.gl_pathc; ++i) - printf ("%s%s%s\n", quotes ? "`" : "", g.gl_pathv[i], + for (i = 0; i < g.gl_offs + g.gl_pathc; ++i) + printf ("%s%s%s\n", quotes ? "`" : "", + g.gl_pathv[i] ? g.gl_pathv[i] : "(null)", quotes ? "'" : ""); } return 0; diff --git a/posix/globtest.sh b/posix/globtest.sh index 4a009cc92b..e2ba320358 100755 --- a/posix/globtest.sh +++ b/posix/globtest.sh @@ -27,9 +27,9 @@ export LANG testdir=$TMPDIR/globtest-dir testout=$TMPDIR/globtest-out -trap 'rm -fr $testdir $testout' 1 2 3 15 +trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15 -rm -fr $testdir +rm -fr $testdir 2>/dev/null mkdir $testdir echo 1 > $testdir/file1 echo 2 > $testdir/file2 @@ -39,6 +39,8 @@ echo 5 > $testdir/.file5 echo 6 > $testdir/'*file6' mkdir $testdir/dir1 mkdir $testdir/dir2 +test -d $testdir/noread || mkdir $testdir/noread +chmod a-r $testdir/noread echo 1_1 > $testdir/dir1/file1_1 echo 1_2 > $testdir/dir1/file1_2 @@ -56,6 +58,7 @@ cat <<"EOF" | cmp - $testout || result=1 `dir2' `file1' `file2' +`noread' `~file4' EOF @@ -70,6 +73,7 @@ cat <<"EOF" | cmp - $testout || result=1 `dir2' `file1' `file2' +`noread' `~file4' EOF @@ -84,6 +88,7 @@ cat <<"EOF" | cmp - $testout || result=1 `dir2/' `file1' `file2' +`noread/' `~file4' EOF @@ -101,6 +106,7 @@ cat <<"EOF" | cmp - $testout || result=1 `dir2' `file1' `file2' +`noread' `~file4' EOF @@ -201,6 +207,24 @@ cat <<"EOF" | cmp - $testout || result=1 `dir1/file1_2' EOF +# Test subdirs with [ .. ] +${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ +${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" | +sort > $testout +cat <<"EOF" | cmp - $testout || result=1 +`dir1/file1_1' +`dir1/file1_2' +EOF + +# Test ']' inside bracket expression +${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ +${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" | +sort > $testout +cat <<"EOF" | cmp - $testout || result=1 +`dir1/file1_1' +`dir1/file1_2' +EOF + # Test tilde expansion ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ ${common_objpfx}posix/globtest -q -t "$testdir" "~" | @@ -243,6 +267,14 @@ cat <<"EOF" | cmp - $testout || result=1 GLOB_NOMATCH EOF +# Matching \*file6 should find *file6 +${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ +${common_objpfx}posix/globtest "$testdir" "\*file6" | +sort > $testout +cat <<"EOF" | cmp - $testout || result=1 +`*file6' +EOF + # Try a recursive failed search ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ ${common_objpfx}posix/globtest -e "$testdir" "a*/*" | @@ -251,6 +283,44 @@ cat <<"EOF" | cmp - $testout || result=1 GLOB_NOMATCH EOF +# ... with GLOB_ERR +${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ +${common_objpfx}posix/globtest -E "$testdir" "a*/*" | +sort > $testout +cat <<"EOF" | cmp - $testout || result=1 +GLOB_NOMATCH +EOF + +# Try a recursive search in unreadable directory +${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ +${common_objpfx}posix/globtest "$testdir" "noread/*" | +sort > $testout +cat <<"EOF" | cmp - $testout || result=1 +GLOB_NOMATCH +EOF + +${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ +${common_objpfx}posix/globtest "$testdir" "noread*/*" | +sort > $testout +cat <<"EOF" | cmp - $testout || result=1 +GLOB_NOMATCH +EOF + +# ... with GLOB_ERR +${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ +${common_objpfx}posix/globtest -E "$testdir" "noread/*" | +sort > $testout +cat <<"EOF" | cmp - $testout || result=1 +GLOB_ABORTED +EOF + +${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ +${common_objpfx}posix/globtest -E "$testdir" "noread*/*" | +sort > $testout +cat <<"EOF" | cmp - $testout || result=1 +GLOB_ABORTED +EOF + # Try multiple patterns (GLOB_APPEND) ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" | @@ -279,9 +349,11 @@ sort > $testout cat <<"EOF" | cmp - $testout || result=1 `dir1/blahblah' `dir2/blahblah' +`noread/blahblah' EOF if test $result -eq 0; then + chmod 777 $testdir/noread rm -fr $testdir $testout fi |