aboutsummaryrefslogtreecommitdiff
path: root/src/librc
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-03-08 13:06:29 +0000
committerRoy Marples <roy@marples.name>2008-03-08 13:06:29 +0000
commit4742e1ec696efad9f786d1b46f0fa9e787622539 (patch)
tree9122cf953789cc40778aca8fa64c7b957754ce1d /src/librc
parent072eca42991db8947173ee9aadbf46cbb7398e90 (diff)
d_type is not portable across filesystems.
Diffstat (limited to 'src/librc')
-rw-r--r--src/librc/librc.c29
1 files 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);