From 4742e1ec696efad9f786d1b46f0fa9e787622539 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sat, 8 Mar 2008 13:06:29 +0000 Subject: d_type is not portable across filesystems. --- src/librc/librc.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/librc/librc.c b/src/librc/librc.c index c6280d15..7344e375 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -114,6 +114,9 @@ static bool rm_dir (const char *pathname, bool top) { DIR *dp; struct dirent *d; + char *tmp = NULL; + struct stat s; + bool retval = true; if ((dp = opendir (pathname)) == NULL) return (false); @@ -121,25 +124,33 @@ static bool rm_dir (const char *pathname, bool top) errno = 0; while (((d = readdir (dp)) != NULL) && errno == 0) { if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0) { - char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL); - if (d->d_type == DT_DIR) { + free (tmp); + tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL); + + if (stat (tmp, &s) != 0) { + retval = false; + break; + } + + if (S_ISDIR (s.st_mode)) { if (! rm_dir (tmp, true)) { - free (tmp); - closedir (dp); - return (false); + retval = false; + break; } } else { if (unlink (tmp)) { - free (tmp); - closedir (dp); - return (false); + retval = false; + break; } } - free (tmp); } } closedir (dp); + free (tmp); + + if (! retval) + return (false); if (top && rmdir (pathname) != 0) return (false); -- cgit v1.2.3