d_type is not portable across filesystems.
This commit is contained in:
parent
072eca4299
commit
4742e1ec69
@ -114,6 +114,9 @@ static bool rm_dir (const char *pathname, bool top)
|
|||||||
{
|
{
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
struct dirent *d;
|
struct dirent *d;
|
||||||
|
char *tmp = NULL;
|
||||||
|
struct stat s;
|
||||||
|
bool retval = true;
|
||||||
|
|
||||||
if ((dp = opendir (pathname)) == NULL)
|
if ((dp = opendir (pathname)) == NULL)
|
||||||
return (false);
|
return (false);
|
||||||
@ -121,25 +124,33 @@ static bool rm_dir (const char *pathname, bool top)
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
while (((d = readdir (dp)) != NULL) && errno == 0) {
|
while (((d = readdir (dp)) != NULL) && errno == 0) {
|
||||||
if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0) {
|
if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0) {
|
||||||
char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL);
|
free (tmp);
|
||||||
if (d->d_type == DT_DIR) {
|
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))
|
if (! rm_dir (tmp, true))
|
||||||
{
|
{
|
||||||
free (tmp);
|
retval = false;
|
||||||
closedir (dp);
|
break;
|
||||||
return (false);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (unlink (tmp)) {
|
if (unlink (tmp)) {
|
||||||
free (tmp);
|
retval = false;
|
||||||
closedir (dp);
|
break;
|
||||||
return (false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free (tmp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir (dp);
|
closedir (dp);
|
||||||
|
free (tmp);
|
||||||
|
|
||||||
|
if (! retval)
|
||||||
|
return (false);
|
||||||
|
|
||||||
if (top && rmdir (pathname) != 0)
|
if (top && rmdir (pathname) != 0)
|
||||||
return (false);
|
return (false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user