about summary refs log tree commit diff
path: root/sysdeps/generic/glob.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-07-20 17:25:48 +0000
committerUlrich Drepper <drepper@redhat.com>1998-07-20 17:25:48 +0000
commita9ddb79305d6346fdf2bcb1772213987d53c0bc5 (patch)
tree113c7be7f13b28e6be9dcd9c4a84a0d4875a8e5c /sysdeps/generic/glob.c
parent8f1c9b09f915b52c7c90c111c3e5e7a995cf8a78 (diff)
downloadglibc-a9ddb79305d6346fdf2bcb1772213987d53c0bc5.tar.gz
glibc-a9ddb79305d6346fdf2bcb1772213987d53c0bc5.tar.xz
glibc-a9ddb79305d6346fdf2bcb1772213987d53c0bc5.zip
Update.
1998-07-20 17:09  Ulrich Drepper  <drepper@cygnus.com>

	* shlib-versions: Remove definition for libSegFault.

	* memory.texi: Comment out the relocating allocator description.
	* manual/signal.texi: Remove reference to relocating allocator.
	* manual/top-menu.texi: Regenerated.

	* posix/fnmatch.c: Implement [: :] and change to recognize
	^ as negation only when not _POSIXLY_CORRECT.

	* sysdeps/generic/glob.c: Add several optimizations.

	* posix/glob.h: Undefine __PMT to prevent warnings.
	Reported by Roland McGrath.

	* posix/regex.c: Define namespace macros only for _LIBC.

	* sysdeps/arm/dl-machine.h: Fix typo.

	* sysdeps/unix/sysv/sysv4/solaris2/sigpending.c: New file.
	* sysdeps/unix/sysv/sysv4/solaris2/sigstack.c: New file.
	* sysdeps/unix/sysv/sysv4/solaris2/sigwaitinfo.c: New file.
	* sysdeps/unix/sysv/sysv4/solaris2/syscalls.list: Add sigaltstack,
	sigpending, sigqueue, and sigtimedwait.
	* sysdeps/unix/sysv/sysv4/solaris2/sparc/sparc32/syscall.S: New file.

	* timezone/leapseconds: Update from tzdata1998f.

1998-07-18  Mark Kettenis  <kettenis@phys.uva.nl>

	* stdio/stdio.h [__USE_GNU]: Add prototype for fputs_unlocked.
	* stdio/Versions [GLIBC_2.1]: Add fputs_unlocked.
	* libio/stdio.h: Fix typo.

1998-07-19  Roland McGrath  <roland@baalperazim.frob.com>

	* sysdeps/mach/hurd/dl-sysdep.c (_dl_sysdep_start): #if 0 out the
	magic memobj port arg parsing stuff.  Fix it someday when we are ready
	to really use it.
	(_dl_sysdep_output): New function, modified from _dl_sysdep_error.
	(_dl_sysdep_error, _dl_sysdep_message, _dl_sysdep_fatal): Removed.

1998-07-19  Roland McGrath  <roland@baalperazim.frob.com>

	* stdio/fputs.c: Add fputs_unlocked as weak alias for fputs.

1998-07-19  Roland McGrath  <roland@baalperazim.frob.com>

	* sysdeps/posix/sigsuspend.c: Define __sigsuspend with sigsuspend as
	a weak alias.
	* sysdeps/mach/hurd/sigsuspend.c: Likewise.
	* sysdeps/generic/sigsuspend.c: Likewise.

1998-07-19  Roland McGrath  <roland@baalperazim.frob.com>

	* sysdeps/mach/hurd/i386/sigcontextinfo.h: New file.

1998-07-19  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* Makerules (map-file): Don't use $(wildcard) to find the
	generated version script, instead look in $(version-maps).
	($(common-objpfx)libc.so): Only depend on libc.map if versioning
	is used.
	* extra-lib.mk ($(objpfx)$(lib).so): Only depend on version script
	if versioning is used.  Don't use $(wildcard) to find the
	generated version script, instead look in $(verson-maps).

1998-07-17  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* sysdeps/generic/segfault.c: Rename GET_EIP to GET_PC.  Remove
	unused function handle.
	* sysdeps/generic/sigcontextinfo.h: Rename GET_EIP to GET_PC.
	* sysdeps/unix/sysv/linux/i386/sigcontextinfo.h: Likewise.
	* debug/catchsegv.sh: Fix argument processing, quoting and various
	typos.  Put the crash info always in the current directory.  Find
	program in $PATH if it contains no directory component.
	* Makerules (install-lib.so-versioned,
	install-lib.so-unversioned): New variables.
	(install-lib-nosubdir): Depend on unversioned libs in
	slibdir, not libdir.

1998-07-19  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* Make-dist (+tsrcs): Remove references to %-map variables and
	*.map files.  Add Versions in subdirs.
	* Makerules (distinfo-vars): Don't write out %-map variables.

1998-07-20 13:55  Ulrich Drepper  <drepper@cygnus.com>

	* inet/protocols/rwhod.h: Remove definition of _PATH_RWHODIR.
	Include <paths.h> instead.
	* sysdeps/generic/paths.h: Define _PATH_RWHODIR.
	* sysdeps/unix/sysv/linux/paths.h: Likewise.
	Reported by Dale Scheetz <dwarf@polaris.net>.

1998-07-17 21:44  Ulrich Drepper  <drepper@cygnus.com>

	* catgets/open_catalog.c: Strictly check whether catalog file is
	larger enough for the data.  Reported by Andries.Brouwer@cwi.nl.
Diffstat (limited to 'sysdeps/generic/glob.c')
-rw-r--r--sysdeps/generic/glob.c190
1 files changed, 113 insertions, 77 deletions
diff --git a/sysdeps/generic/glob.c b/sysdeps/generic/glob.c
index 70d125c200..9182c0585a 100644
--- a/sysdeps/generic/glob.c
+++ b/sysdeps/generic/glob.c
@@ -797,10 +797,10 @@ glob (pattern, flags, errfunc, pglob)
       int i;
       struct stat st;
       for (i = oldcount; i < pglob->gl_pathc; ++i)
-	if (((flags & GLOB_ALTDIRFUNC) ?
-	     (*pglob->gl_stat) (pglob->gl_pathv[i], &st) :
-	     __stat (pglob->gl_pathv[i], &st)) == 0 &&
-	    S_ISDIR (st.st_mode))
+	if (((flags & GLOB_ALTDIRFUNC)
+	     ? (*pglob->gl_stat) (pglob->gl_pathv[i], &st)
+	     : __stat (pglob->gl_pathv[i], &st)) == 0
+	    && S_ISDIR (st.st_mode))
 	  {
  	    size_t len = strlen (pglob->gl_pathv[i]) + 2;
 	    char *new = realloc (pglob->gl_pathv[i], len);
@@ -958,7 +958,7 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
      int (*errfunc) __P ((const char *, int));
      glob_t *pglob;
 {
-  __ptr_t stream;
+  __ptr_t stream = NULL;
 
   struct globlink
     {
@@ -970,92 +970,127 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
   int meta;
   int save;
 
-  stream = ((flags & GLOB_ALTDIRFUNC) ?
- 	    (*pglob->gl_opendir) (directory) :
-	    (__ptr_t) opendir (directory));
-  if (stream == NULL)
+  meta = __glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE));
+  if (meta == 0)
     {
-      if ((errfunc != NULL && (*errfunc) (directory, errno)) ||
-	  (flags & GLOB_ERR))
-	return GLOB_ABORTED;
+      if (flags & (GLOB_NOCHECK|GLOB_NOMAGIC))
+	/* We need not do any tests.  The PATTERN contains no meta
+	   characters and we must not return an error therefore the
+	   result will always contain exactly the one name.  */
+	flags |= GLOB_NOCHECK;
+      else
+	{
+	  /* Since we use the normal file functions we can also use stat()
+	     to verify the file is there.  */
+	  struct stat st;
+	  size_t patlen = strlen (pattern);
+	  size_t dirlen = strlen (directory);
+	  char *fullname = __alloca (dirlen + 1 + patlen + 1);
+
+# ifdef HAVE_MEMPCPY
+	  mempcpy (mempcpy (mempcpy (fullname, directory, dirlen),
+			    "/", 1),
+		   pattern, patlen + 1);
+# else
+	  memcpy (fullname, directory, dirlen);
+	  fullname[dirlen] = '/';
+	  memcpy (&fullname[dirlen + 1], pattern, patlen + 1);
+# endif
+	  if (((flags & GLOB_ALTDIRFUNC)
+	       ? (*pglob->gl_stat) (fullname, &st)
+	       : __stat (fullname, &st)) == 0)
+	    /* We found this file to be existing.  No tell the rest
+	       of the function to copy this name into the result.  */
+	    flags |= GLOB_NOCHECK;
+	}
+
       nfound = 0;
-      meta = 0;
-    }
-  else if (pattern[0] == '\0')
-    {
-      /* This is a special case for matching directories like in
-	 "*a/".  */
-      names = (struct globlink *) __alloca (sizeof (struct globlink));
-      names->name = (char *) malloc (1);
-      if (names->name == NULL)
-	goto memory_error;
-      names->name[0] = '\0';
-      names->next = NULL;
-      nfound = 1;
-      meta = 0;
     }
   else
     {
-      nfound = 0;
-      meta = __glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE));
-      if(meta)
-	flags |= GLOB_MAGCHAR;
-
-      while (1)
+      if (pattern[0] == '\0')
 	{
-	  const char *name;
-	  size_t len;
-	  struct dirent *d = ((flags & GLOB_ALTDIRFUNC) ?
-			      (*pglob->gl_readdir) (stream) :
-			      readdir ((DIR *) stream));
-	  if (d == NULL)
-	    break;
-	  if (! REAL_DIR_ENTRY (d))
-	    continue;
+	  /* This is a special case for matching directories like in
+	     "*a/".  */
+	  names = (struct globlink *) __alloca (sizeof (struct globlink));
+	  names->name = (char *) malloc (1);
+	  if (names->name == NULL)
+	    goto memory_error;
+	  names->name[0] = '\0';
+	  names->next = NULL;
+	  nfound = 1;
+	  meta = 0;
+	}
+      else
+	{
+	  stream = ((flags & GLOB_ALTDIRFUNC)
+		    ? (*pglob->gl_opendir) (directory)
+		    : (__ptr_t) opendir (directory));
+	  if (stream == NULL)
+	    {
+	      if ((errfunc != NULL && (*errfunc) (directory, errno))
+		  || (flags & GLOB_ERR))
+		return GLOB_ABORTED;
+	      nfound = 0;
+	      meta = 0;
+	    }
+	  else
+	    {
+	      int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0)
+			       | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)
+#if defined _AMIGA || defined VMS
+				   | FNM_CASEFOLD
+#endif
+				   );
+	      nfound = 0;
+	      flags |= GLOB_MAGCHAR;
+
+	      while (1)
+		{
+		  const char *name;
+		  size_t len;
+		  struct dirent *d = ((flags & GLOB_ALTDIRFUNC)
+				      ? (*pglob->gl_readdir) (stream)
+				      : readdir ((DIR *) stream));
+		  if (d == NULL)
+		    break;
+		  if (! REAL_DIR_ENTRY (d))
+		    continue;
 
 #ifdef HAVE_D_TYPE
-	  /* If we shall match only directories use the information
-	     provided by the dirent call if possible.  */
-	  if ((flags & GLOB_ONLYDIR)
-	      && d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
-	    continue;
+		  /* If we shall match only directories use the information
+		     provided by the dirent call if possible.  */
+		  if ((flags & GLOB_ONLYDIR)
+		      && d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
+		    continue;
 #endif
 
-	  name = d->d_name;
+		  name = d->d_name;
 
-	  if ((!meta && strcmp (pattern, name) == 0)
-	      || fnmatch (pattern, name,
-			  (!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) |
-			  ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)
-#if defined _AMIGA || defined VMS
-			  | FNM_CASEFOLD
-#endif
-			 ) == 0)
-	    {
-	      struct globlink *new
-		= (struct globlink *) __alloca (sizeof (struct globlink));
-	      len = NAMLEN (d);
-	      new->name = (char *) malloc (len + 1);
-	      if (new->name == NULL)
-		goto memory_error;
+		  if (fnmatch (pattern, name, fnm_flags) == 0)
+		    {
+		      struct globlink *new = (struct globlink *)
+			__alloca (sizeof (struct globlink));
+		      len = NAMLEN (d);
+		      new->name = (char *) malloc (len + 1);
+		      if (new->name == NULL)
+			goto memory_error;
 #ifdef HAVE_MEMPCPY
-	      *((char *) mempcpy ((__ptr_t) new->name, name, len)) = '\0';
+		      *((char *) mempcpy ((__ptr_t) new->name, name, len))
+			= '\0';
 #else
-	      memcpy ((__ptr_t) new->name, name, len);
-	      new->name[len] = '\0';
+		      memcpy ((__ptr_t) new->name, name, len);
+		      new->name[len] = '\0';
 #endif
-	      new->next = names;
-	      names = new;
-	      ++nfound;
-	      if (!meta)
-		break;
+		      new->next = names;
+		      names = new;
+		      ++nfound;
+		    }
+		}
 	    }
 	}
     }
 
-  if (nfound == 0 && (flags & GLOB_NOMAGIC) && !meta)
-    flags |= GLOB_NOCHECK;
-
   if (nfound == 0 && (flags & GLOB_NOCHECK))
     {
       size_t len = strlen (pattern);
@@ -1096,10 +1131,11 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
     }
 
   save = errno;
-  if (flags & GLOB_ALTDIRFUNC)
-    (*pglob->gl_closedir) (stream);
-  else
-    closedir ((DIR *) stream);
+  if (stream != NULL)
+    if (flags & GLOB_ALTDIRFUNC)
+      (*pglob->gl_closedir) (stream);
+    else
+      closedir ((DIR *) stream);
   __set_errno (save);
 
   return nfound == 0 ? GLOB_NOMATCH : 0;