]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix two problems with GLOB_DOOFFS.
authorUlrich Drepper <drepper@redhat.com>
Thu, 23 Jul 1998 11:33:18 +0000 (11:33 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 23 Jul 1998 11:33:18 +0000 (11:33 +0000)
posix/glob.c

index 85747f5a9dfd0fdb691871b4b7f90bd2605c036d..36282805efb2f5ee003f3c9ed2bfa67dff07fb5a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public License as
@@ -682,7 +682,7 @@ glob (pattern, flags, errfunc, pglob)
         appending the results to PGLOB.  */
       for (i = 0; i < dirs.gl_pathc; ++i)
        {
-         int oldcount;
+         int old_pathc;
 
 #ifdef SHELL
          {
@@ -698,7 +698,7 @@ glob (pattern, flags, errfunc, pglob)
          }
 #endif /* SHELL.  */
 
-         oldcount = pglob->gl_pathc;
+         old_pathc = pglob->gl_pathc;
          status = glob_in_dir (filename, dirs.gl_pathv[i],
                                ((flags | GLOB_APPEND)
                                 & ~(GLOB_NOCHECK | GLOB_ERR)),
@@ -716,8 +716,8 @@ glob (pattern, flags, errfunc, pglob)
 
          /* Stick the directory on the front of each name.  */
          if (prefix_array (dirs.gl_pathv[i],
-                           &pglob->gl_pathv[oldcount],
-                           pglob->gl_pathc - oldcount))
+                           &pglob->gl_pathv[old_pathc],
+                           pglob->gl_pathc - old_pathc))
            {
              globfree (&dirs);
              globfree (pglob);
@@ -770,9 +770,14 @@ glob (pattern, flags, errfunc, pglob)
       if (dirlen > 0)
        {
          /* Stick the directory on the front of each name.  */
+         int ignore = oldcount;
+
+         if ((flags & GLOB_DOOFFS) && ignore < pglob->gl_offs)
+           ignore = pglob->gl_offs;
+
          if (prefix_array (dirname,
-                           &pglob->gl_pathv[oldcount],
-                           pglob->gl_pathc - oldcount))
+                           &pglob->gl_pathv[ignore],
+                           pglob->gl_pathc - ignore))
            {
              globfree (pglob);
              return GLOB_NOSPACE;
@@ -804,10 +809,17 @@ glob (pattern, flags, errfunc, pglob)
     }
 
   if (!(flags & GLOB_NOSORT))
-    /* Sort the vector.  */
-    qsort ((__ptr_t) &pglob->gl_pathv[oldcount],
-          pglob->gl_pathc - oldcount,
-          sizeof (char *), collated_compare);
+    {
+      /* Sort the vector.  */
+      int non_sort = oldcount;
+
+      if ((flags & GLOB_DOOFFS) && pglob->gl_offs > oldcount)
+       non_sort = pglob->gl_offs;
+
+      qsort ((__ptr_t) &pglob->gl_pathv[non_sort],
+            pglob->gl_pathc - non_sort,
+            sizeof (char *), collated_compare);
+    }
 
   return 0;
 }