aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-07-27 22:28:11 +0000
committerUlrich Drepper <drepper@redhat.com>1998-07-27 22:28:11 +0000
commitc9243dacea19b7dcf36bb69ca83877d3ea905831 (patch)
tree4fdc2ae865b50e03bb503851e3c219cf43057a28
parent3f62b69af3f0f61299ac7bcbc7c3b35cbd16cf4a (diff)
downloadglibc-c9243dacea19b7dcf36bb69ca83877d3ea905831.zip
glibc-c9243dacea19b7dcf36bb69ca83877d3ea905831.tar.gz
glibc-c9243dacea19b7dcf36bb69ca83877d3ea905831.tar.bz2
Update.
1998-07-27 22:25 Ulrich Drepper <drepper@cygnus.com> * sysdeps/generic/glob.c: Handle ~ and ~NAME case correctly. * posix/globtest.sh: Also add directories with NSS modules into the library path.
-rw-r--r--ChangeLog7
-rwxr-xr-xposix/globtest.sh77
-rw-r--r--sysdeps/generic/glob.c61
3 files changed, 106 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index bd23545..98f0524 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+1998-07-27 22:25 Ulrich Drepper <drepper@cygnus.com>
+
+ * sysdeps/generic/glob.c: Handle ~ and ~NAME case correctly.
+
+ * posix/globtest.sh: Also add directories with NSS modules into the
+ library path.
+
1998-07-27 17:42 Ulrich Drepper <drepper@cygnus.com>
* nss/nss_files/files-parse.c (INT_FIELD): Use strtoul instead of
diff --git a/posix/globtest.sh b/posix/globtest.sh
index 1a417aa..919c584 100755
--- a/posix/globtest.sh
+++ b/posix/globtest.sh
@@ -4,6 +4,9 @@ common_objpfx=$1; shift
elf_objpfx=$1; shift
rtld_installed_name=$1; shift
+# We have to find the libc and the NSS modules.
+library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis
+
# Since we use `osrt' we must make sure to use the same locale everywhere.
LC_ALL=C
export LC_ALL
@@ -35,7 +38,7 @@ echo 1_2 > $testdir/dir1/file1_2
result=0
# Normal test
-${elf_objpfx}${rtld_installed_name} --library-path ${common_objpfx} \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -49,7 +52,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Don't let glob sort it
-${elf_objpfx}${rtld_installed_name} --library-path ${common_objpfx} \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -s "$testdir" "*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -63,7 +66,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Mark directories
-${elf_objpfx}${rtld_installed_name} --library-path ${common_objpfx} \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -m "$testdir" "*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -77,7 +80,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Find files starting with .
-${elf_objpfx}${rtld_installed_name} --library-path ${common_objpfx} \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -p "$testdir" "*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -94,7 +97,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Test braces
-${elf_objpfx}${rtld_installed_name} --library-path ${common_objpfx} \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -103,7 +106,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Test NOCHECK
-${elf_objpfx}${rtld_installed_name} --library-path ${common_objpfx} \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -c "$testdir" "abc" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -111,7 +114,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Test NOMAGIC without magic characters
-${elf_objpfx}${rtld_installed_name} --library-path ${common_objpfx} \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -g "$testdir" "abc" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -119,7 +122,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Test NOMAGIC with magic characters
-${elf_objpfx}${rtld_installed_name} --library-path ${common_objpfx} \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -g "$testdir" "abc*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -127,7 +130,7 @@ GLOB_NOMATCH
EOF
# Test subdirs correctly
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -136,7 +139,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Test subdirs for invalid names
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/1" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -144,7 +147,7 @@ GLOB_NOMATCH
EOF
# Test subdirs with wildcard
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -152,7 +155,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Test subdirs with ?
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -160,21 +163,21 @@ cat <<"EOF" | cmp - $testout || result=1
`dir1/file1_2'
EOF
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
`dir1/file1_1'
EOF
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*-/*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
GLOB_NOMATCH
EOF
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*-" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -182,7 +185,7 @@ GLOB_NOMATCH
EOF
# Test subdirs with ?
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -191,28 +194,28 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Test tilde expansion
-#${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
-#${common_objpfx}posix/globtest -q -t "$testdir" "~" |
-#sort >$testout
-#echo ~ > $testout2
-#cmp $testout2 $testout || result=1
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
+${common_objpfx}posix/globtest -q -t "$testdir" "~" |
+sort >$testout
+echo ~ > $testout2
+cmp $testout2 $testout || result=1
# Test tilde expansion with trailing slash
-#${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
-#${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
-#sort > $testout
-#echo ~/ > $testout2
-#cmp $testout2 $testout || result=1
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
+${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
+sort > $testout
+echo ~/ > $testout2
+cmp $testout2 $testout || result=1
# Test tilde expansion with username
-#${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
-#${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
-#sort > $testout
-#eval echo ~$USER > $testout2
-#cmp $testout2 $testout || result=1
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
+${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
+sort > $testout
+eval echo ~$USER > $testout2
+cmp $testout2 $testout || result=1
# Tilde expansion shouldn't match a file
-#${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+#${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
#${common_objpfx}posix/globtest -t "$testdir" "~file4" |
#sort > $testout
#cat <<"EOF" | cmp - $testout || result=1
@@ -220,7 +223,7 @@ EOF
#EOF
# Matching \** should only find *file6
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "\**" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -228,7 +231,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# ... unless NOESCAPE is used, in which case it shouldn't match anything.
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -e "$testdir" "\**" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -236,7 +239,7 @@ GLOB_NOMATCH
EOF
# Try a recursive failed search
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -244,7 +247,7 @@ GLOB_NOMATCH
EOF
# Try multiple patterns (GLOB_APPEND)
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
@@ -254,7 +257,7 @@ cat <<"EOF" | cmp - $testout || result=1
EOF
# Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
-${elf_objpfx}${rtld_installed_name} --library-path $common_objpfx \
+${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
sort > $testout
cat <<"EOF" | cmp - $testout || result=1
diff --git a/sysdeps/generic/glob.c b/sysdeps/generic/glob.c
index 63347bd..5f96554 100644
--- a/sysdeps/generic/glob.c
+++ b/sysdeps/generic/glob.c
@@ -240,6 +240,7 @@ extern char *alloca ();
#endif
#ifdef _LIBC
+# define strdup(str) __strdup (str)
# define sysconf(id) __sysconf (id)
# define closedir(dir) __closedir (dir)
# define opendir(name) __opendir (name)
@@ -494,10 +495,13 @@ glob (pattern, flags, errfunc, pglob)
case is nothing but a notation for a directory. */
if ((flags & GLOB_TILDE) && pattern[0] == '~')
{
- dirname = pattern;
+ dirname = (char *) pattern;
dirlen = strlen (pattern);
- filename = "";
+ /* Set FILENAME to NULL as a special flag. This is ugly but
+ other solutions would requiremuch more code. We test for
+ this special case below. */
+ filename = NULL;
}
else
{
@@ -686,6 +690,59 @@ glob (pattern, flags, errfunc, pglob)
}
#endif /* Not VMS. */
+ /* Now test whether we looked for "~" or "~NAME". In this case we
+ can give the answer now. */
+ if (filename == NULL)
+ {
+ struct stat st;
+
+ /* Return the directory if we don't check for error or if it exists. */
+ if ((flags & GLOB_NOCHECK)
+ || (((flags & GLOB_ALTDIRFUNC)
+ ? (*pglob->gl_stat) (dirname, &st)
+ : __stat (dirname, &st)) == 0
+ && S_ISDIR (st.st_mode)))
+ {
+ pglob->gl_pathv
+ = (char **) realloc (pglob->gl_pathv,
+ (pglob->gl_pathc +
+ ((flags & GLOB_DOOFFS) ?
+ pglob->gl_offs : 0) +
+ 1 + 1) *
+ sizeof (char *));
+ if (pglob->gl_pathv == NULL)
+ return GLOB_NOSPACE;
+
+ if (flags & GLOB_DOOFFS)
+ while (pglob->gl_pathc < pglob->gl_offs)
+ pglob->gl_pathv[pglob->gl_pathc++] = NULL;
+
+#if defined HAVE_STRDUP || defined _LIBC
+ pglob->gl_pathv[pglob->gl_pathc] = strdup (dirname);
+#else
+ {
+ size_t len = strlen (dirname) + 1;
+ char *dircopy = malloc (len);
+ if (dircopy != NULL)
+ pglob->gl_pathv[pglob->gl_pathc] = memcpy (dircopy, dirname,
+ len);
+ }
+#endif
+ if (pglob->gl_pathv[pglob->gl_pathc] == NULL)
+ {
+ free (pglob->gl_pathv);
+ return GLOB_NOSPACE;
+ }
+ pglob->gl_pathv[++pglob->gl_pathc] = NULL;
+ pglob->gl_flags = flags;
+
+ return 0;
+ }
+
+ /* Not found. */
+ return GLOB_NOMATCH;
+ }
+
if (__glob_pattern_p (dirname, !(flags & GLOB_NOESCAPE)))
{
/* The directory name contains metacharacters, so we