diff options
author | Jim Meyering <jim@meyering.net> | 2002-08-29 09:42:43 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2002-08-29 09:42:43 +0000 |
commit | 9a9e0503a26a2076caa48422cbcc6ae02aeb3721 (patch) | |
tree | 87ade29b56c3c792b171c7a10050065d8dd33d27 /src | |
parent | cd79080f4ab954f6a67be7b3d7d43b9526a2fe76 (diff) | |
download | coreutils-9a9e0503a26a2076caa48422cbcc6ae02aeb3721.tar.xz |
(remove_cwd_entries): Detect and diagnose readdir
failures. On some systems (at least EMC Celerra and Solaris5.8),
this appears to be necessary.
Diffstat (limited to 'src')
-rw-r--r-- | src/remove.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/remove.c b/src/remove.c index f09184e35..15ea10d2f 100644 --- a/src/remove.c +++ b/src/remove.c @@ -810,12 +810,27 @@ remove_cwd_entries (char **subdir, struct stat *subdir_sb, while (1) { - struct dirent *dp = readdir (dirp); + struct dirent *dp; enum RM_status tmp_status; const char *f; - if (dp == NULL) - break; + /* Set errno to zero so we can distinguish between a readdir failure + and when readdir simply finds that there are no more entries. */ + errno = 0; + if ((dp = readdir (dirp)) == NULL) + { + if (errno) + { + /* Save/restore errno across closedir call. */ + int e = errno; + CLOSEDIR (dirp); + errno = e; + + /* Arrange to give a diagnostic after exiting this loop. */ + dirp = NULL; + } + break; + } f = dp->d_name; if (DOT_OR_DOTDOT (f)) @@ -871,8 +886,10 @@ remove_cwd_entries (char **subdir, struct stat *subdir_sb, break; } - if (CLOSEDIR (dirp) != 0) + if (dirp == NULL || CLOSEDIR (dirp) != 0) { + /* Note that this diagnostic serves for both readdir + and closedir failures. */ error (0, errno, _("reading directory %s"), quote (full_filename ("."))); status = RM_ERROR; } |