1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-08-13 13:45:55 +02:00

(remove_cwd_entries): Detect and diagnose readdir

failures.  On some systems (at least EMC Celerra and Solaris5.8),
this appears to be necessary.
This commit is contained in:
Jim Meyering
2002-08-29 09:42:43 +00:00
parent cd79080f4a
commit 9a9e0503a2
+21 -4
View File
@@ -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;
}