tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853)

This commit is contained in:
Reverend Homer
2016-12-09 10:04:30 +01:00
committed by Martin Pitt
parent 9258a1cae3
commit 8fb3f00997
20 changed files with 46 additions and 118 deletions
+4 -11
View File
@@ -17,7 +17,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
@@ -28,6 +27,7 @@
#include "btrfs-util.h"
#include "cgroup-util.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "log.h"
#include "macro.h"
@@ -43,6 +43,7 @@ static bool is_physical_fs(const struct statfs *sfs) {
int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int ret = 0, r;
struct statfs sfs;
@@ -78,19 +79,10 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
return errno == ENOENT ? 0 : -errno;
}
for (;;) {
struct dirent *de;
FOREACH_DIRENT_ALL(de, d, return -errno) {
bool is_dir;
struct stat st;
errno = 0;
de = readdir(d);
if (!de) {
if (errno > 0 && ret == 0)
ret = -errno;
return ret;
}
if (streq(de->d_name, ".") || streq(de->d_name, ".."))
continue;
@@ -178,6 +170,7 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
}
}
}
return ret;
}
int rm_rf(const char *path, RemoveFlags flags) {