summaryrefslogtreecommitdiff
path: root/src/basic/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-19 23:58:17 +0200
committerLennart Poettering <lennart@poettering.net>2015-10-22 01:59:24 +0200
commitac7edd91670ae859cda6e9b2b97fd87f2639433a (patch)
treedb1b1975f91c893cf7a2801c11279f291755071f /src/basic/util.c
parent2dcc3c69a10f76e0ee9185c863d23ee62d481919 (diff)
util: improve dir_is_empty() call
Simplify the call, and add dir_is_populated() as inverse call, in order to make some checks easier to read.
Diffstat (limited to 'src/basic/util.c')
-rw-r--r--src/basic/util.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index 3e90456dd3..c2a2f8dc5c 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -2381,25 +2381,16 @@ bool is_device_path(const char *path) {
int dir_is_empty(const char *path) {
_cleanup_closedir_ DIR *d;
+ struct dirent *de;
d = opendir(path);
if (!d)
return -errno;
- for (;;) {
- struct dirent *de;
-
- errno = 0;
- de = readdir(d);
- if (!de && errno != 0)
- return -errno;
-
- if (!de)
- return 1;
+ FOREACH_DIRENT(de, d, return -errno)
+ return 0;
- if (!hidden_file(de->d_name))
- return 0;
- }
+ return 1;
}
char* dirname_malloc(const char *path) {