summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-08-29 10:42:12 +0000
committerJim Meyering <jim@meyering.net>2002-08-29 10:42:12 +0000
commit649a00e9b8d14fd96ffc64a218f913addf676f9c (patch)
treede39ccd75ccac86c58be80fb3ccf87e116ee8dc0 /src
parent515f184462e354affdf6b7eb8cff80ca27e7aea4 (diff)
downloadcoreutils-649a00e9b8d14fd96ffc64a218f913addf676f9c.tar.xz
(is_empty_dir): Detect and diagnose readdir failures.
Always close directory handle.
Diffstat (limited to 'src')
-rw-r--r--src/remove.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/remove.c b/src/remove.c
index 11df3fa54..a75694c6b 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -522,19 +522,30 @@ is_empty_dir (char const *dir)
{
DIR *dirp = opendir (dir);
if (dirp == NULL)
- return false;
+ {
+ closedir (dirp);
+ return false;
+ }
while (1)
{
- struct dirent *dp = readdir (dirp);
+ struct dirent *dp;
const char *f;
+ errno = 0;
+ dp = readdir (dirp);
if (dp == NULL)
- return true;
+ {
+ closedir (dirp);
+ return errno == 0 ? true : false;
+ }
f = dp->d_name;
if ( ! DOT_OR_DOTDOT (f))
- return false;
+ {
+ closedir (dirp);
+ return false;
+ }
}
}