diff options
author | Jim Meyering <jim@meyering.net> | 1997-10-19 03:09:40 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1997-10-19 03:09:40 +0000 |
commit | a7e650ac125477a58e335da72265a14f6eb531d7 (patch) | |
tree | 49c6ee2dddeeab85b84ae4a403c3d96324d8fb14 /src | |
parent | 53e807719a85db054b9a457f9001f620caf53ec1 (diff) | |
download | coreutils-a7e650ac125477a58e335da72265a14f6eb531d7.tar.xz |
(remove_cwd_entries): Entries in table of processed dir
entries are not malloc'd, so don't have hash cleanup free them.
Rewind dirp upon NULL readdir, required for at least SunOS.
Diffstat (limited to 'src')
-rw-r--r-- | src/rm.c | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -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")); |