chiark / gitweb /
basic: add readdir_no_dot and safe_glob functions
[elogind.git] / src / basic / dirent-util.c
index 6b9d26773ea78868a50fdb662bb6ba8ea559bd64..5bf58bcdc36d442022e1ef6a82965e06aecfcdf2 100644 (file)
@@ -75,3 +75,14 @@ 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;
+
+        for (;;) {
+                d = readdir(dirp);
+                if (d && dot_or_dot_dot(d->d_name))
+                        continue;
+                return d;
+        }
+}