summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/util.c17
-rw-r--r--src/basic/util.h8
2 files changed, 12 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) {
diff --git a/src/basic/util.h b/src/basic/util.h
index ff39eae715..a3ebb987e4 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -358,6 +358,14 @@ bool is_device_path(const char *path);
int dir_is_empty(const char *path);
char* dirname_malloc(const char *path);
+static inline int dir_is_populated(const char *path) {
+ int r;
+ r = dir_is_empty(path);
+ if (r < 0)
+ return r;
+ return !r;
+}
+
char* lookup_uid(uid_t uid);
char* getlogname_malloc(void);
char* getusername_malloc(void);