static int cleanup_recursive(const char *path)
{
- int ret;
+ int ret = 0;
struct stat f;
DIR *dir = NULL;
struct dirent *dent;
char sub_path[PATH_MAX] = {0,};
- ret = lstat(path, &f);
- if (ret)
+ if (access(path, W_OK) < 0)
return -EINVAL;
- if ((f.st_mode & S_IFMT) == S_IFDIR) {
- if (access(path, W_OK) != 0)
- return -EINVAL;
+ if (lstat(path, &f) < 0)
+ return -EINVAL;
+ if ((f.st_mode & S_IFMT) == S_IFDIR) {
dir = opendir(path);
if (!dir)
return -EINVAL;
break;
}
closedir(dir);
- return ret;
} else {
regex_t regex;
if (ret)
return -EINVAL;
- if (!regexec(®ex, path, 0, NULL, 0))
- remove(path);
+ if (!regexec(®ex, path, 0, NULL, 0)) {
+ if (remove(path) < 0)
+ ret = -errno;
+ }
regfree(®ex);
}
- return 0;
+ return ret;
}
int main(int argc, char *argv[])