]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dirent-util: introduce readdir_ensure_type()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jun 2021 19:00:42 +0000 (04:00 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jun 2021 19:19:38 +0000 (04:19 +0900)
src/basic/dirent-util.c
src/basic/dirent-util.h

index 48aced748a9de2da5b82353f1acccf18588f2610..988269896a33db8a77ac6861bf9cff5d7c861d95 100644 (file)
@@ -59,8 +59,20 @@ bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) {
         return endswith(de->d_name, suffix);
 }
 
-struct dirent* readdir_no_dot(DIR *dirp) {
-        struct dirent* d;
+struct dirent *readdir_ensure_type(DIR *d) {
+        struct dirent *de;
+
+        assert(d);
+
+        errno = 0;
+        de = readdir(d);
+        if (de)
+                (void) dirent_ensure_type(d, de);
+        return de;
+}
+
+struct dirent *readdir_no_dot(DIR *dirp) {
+        struct dirent *d;
 
         for (;;) {
                 d = readdir(dirp);
index 07750c39e0270e628045c41f2406e7a0503cec6f..20ab216c0c6defce6eff8a68b47016844465853b 100644 (file)
@@ -13,7 +13,8 @@ int dirent_ensure_type(DIR *d, struct dirent *de);
 bool dirent_is_file(const struct dirent *de) _pure_;
 bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;
 
-struct dirent* readdir_no_dot(DIR *dirp);
+struct dirent *readdir_ensure_type(DIR *d);
+struct dirent *readdir_no_dot(DIR *dirp);
 
 #define FOREACH_DIRENT(de, d, on_error)                                 \
         for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d))   \