]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: improve dir_is_empty() call
authorLennart Poettering <lennart@poettering.net>
Mon, 19 Oct 2015 21:58:17 +0000 (23:58 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 21 Oct 2015 23:59:24 +0000 (01:59 +0200)
Simplify the call, and add dir_is_populated() as inverse call, in order
to make some checks easier to read.

src/basic/util.c
src/basic/util.h

index 3e90456dd3ef73de6221802d7ee1362f2a22e008..c2a2f8dc5cdfc76ca139f05588bd1397ec6939c9 100644 (file)
@@ -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) {
index ff39eae715e9125536a88185d6ae452cce68d81a..a3ebb987e41e352021a8692551ca9388730f12ee 100644 (file)
@@ -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);