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
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
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
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
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
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
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
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
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
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
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
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
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
`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
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
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
#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
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
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
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
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
#endif
#ifdef _LIBC
+# define strdup(str) __strdup (str)
# define sysconf(id) __sysconf (id)
# define closedir(dir) __closedir (dir)
# define opendir(name) __opendir (name)
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
{
}
#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