]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(remove_cwd_entries): Entries in table of processed dir
authorJim Meyering <jim@meyering.net>
Sun, 19 Oct 1997 03:09:40 +0000 (03:09 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 19 Oct 1997 03:09:40 +0000 (03:09 +0000)
entries are not malloc'd, so don't have hash cleanup free them.
Rewind dirp upon NULL readdir, required for at least SunOS.

src/rm.c

index 29b6f1200e55b2c270db2aae522c800b716f5f7a..a333cd1a9a47418c2d5fd4baa92cae319d91ce1b 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -573,17 +573,30 @@ remove_cwd_entries (void)
          enum RM_status tmp_status;
          struct dirent *dp;
 
+/* FILE should be skipped if it is `.' or `..', or if it is in
+   the table, HT, of entries we've already processed.  */
+#define SKIPPABLE(Ht, File) (DOT_OR_DOTDOT(File) \
+                            || (Ht && hash_query_in_table (Ht, File)))
+
          dp = readdir (dirp);
          if (dp == NULL)
-           break;
+           {
+             /* Since we have probably modified the directory since it
+                was opened, readdir returning NULL does not necessarily
+                mean we have read the last entry.  Rewind it and check
+                again.  This happens on SunOS4.1.4 with 254 or more files
+                in a directory.  */
+             rewinddir (dirp);
+             while ((dp = readdir (dirp)) && SKIPPABLE (ht, dp->d_name))
+               {
+                 /* empty */
+               }
+           }
 
-         /* Skip this entry if it's `.' or `..'.  */
-         if (DOT_OR_DOTDOT (dp->d_name))
-           continue;
+         if (dp == NULL)
+           break;
 
-         /* Skip this entry if it's in the table of ones we've already
-            processed.  */
-         if (ht && hash_query_in_table (ht, (dp)->d_name))
+         if (SKIPPABLE (ht, dp->d_name))
            continue;
 
          fspec_init_dp (&fs, dp);
@@ -611,7 +624,7 @@ remove_cwd_entries (void)
 
              if (ht == NULL)
                {
-                 ht = hash_initialize (HT_INITIAL_CAPACITY, free,
+                 ht = hash_initialize (HT_INITIAL_CAPACITY, NULL,
                                        hash_pjw, hash_compare_strings);
                  if (ht == NULL)
                    error (1, 0, _("Memory exhausted"));