]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/fileutils: add xreaddir()
authorKarel Zak <kzak@redhat.com>
Thu, 11 Apr 2019 11:11:53 +0000 (13:11 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 11 Apr 2019 11:11:53 +0000 (13:11 +0200)
Remove duplicate code and keep only one implementation in
include/fileutils.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
include/fileutils.h
lib/path.c
lib/sysfs.c
misc-utils/lsblk.c

index 8a7e662616a0e19dafd47a5c3c3dde67da3c8c45..043f2ca44b43b4ae3e059eb5d173b827ba453c4a 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <dirent.h>
 #include <sys/stat.h>
 
 #include "c.h"
@@ -57,4 +58,18 @@ extern int get_fd_tabsize(void);
 extern int mkdir_p(const char *path, mode_t mode);
 extern char *stripoff_last_component(char *path);
 
+/* This is readdir()-like function, but skips "." and ".." directory entries */
+static inline struct dirent *xreaddir(DIR *dp)
+{
+       struct dirent *d;
+
+       while ((d = readdir(dp))) {
+               if (!strcmp(d->d_name, ".") ||
+                   !strcmp(d->d_name, ".."))
+                       continue;
+               break;
+       }
+       return d;
+}
+
 #endif /* UTIL_LINUX_FILEUTILS */
index a9c47f2a182b0feaa0e1bf3788037093aa702508..00152f54c0ef284313b25520cb23be6944c85bcd 100644 (file)
@@ -910,21 +910,6 @@ int ul_path_writef_u64(struct path_cxt *pc, uint64_t num, const char *path, ...)
 
 }
 
-static struct dirent *xreaddir(DIR *dp)
-{
-       struct dirent *d;
-
-       while ((d = readdir(dp))) {
-               if (!strcmp(d->d_name, ".") ||
-                   !strcmp(d->d_name, ".."))
-                       continue;
-
-               /* blacklist here? */
-               break;
-       }
-       return d;
-}
-
 int ul_path_count_dirents(struct path_cxt *pc, const char *path)
 {
        DIR *dir;
index 6916c2584d47165c5ca622cd57acc85ad42fa2b2..9e336adcf920cdb91ad26ccac6df4c673cb28f1d 100644 (file)
@@ -200,21 +200,6 @@ char *sysfs_blkdev_get_name(struct path_cxt *pc, char *buf, size_t bufsiz)
        return buf;
 }
 
-static struct dirent *xreaddir(DIR *dp)
-{
-       struct dirent *d;
-
-       while ((d = readdir(dp))) {
-               if (!strcmp(d->d_name, ".") ||
-                   !strcmp(d->d_name, ".."))
-                       continue;
-
-               /* blacklist here? */
-               break;
-       }
-       return d;
-}
-
 int sysfs_blkdev_is_partition_dirent(DIR *dir, struct dirent *d, const char *parent_name)
 {
        char path[NAME_MAX + 6 + 1];
index ad5af4721fa729595303f844490b66b1198c2b24..915a062baa0f2dd95c7793e3fda79e9d1280fb16 100644 (file)
@@ -49,6 +49,7 @@
 #include "sysfs.h"
 #include "closestream.h"
 #include "optutils.h"
+#include "fileutils.h"
 
 #include "lsblk.h"
 
@@ -328,24 +329,6 @@ static int is_dm(const char *name)
        return strncmp(name, "dm-", 3) ? 0 : 1;
 }
 
-/* This is readdir()-like function, but skips "." and ".." directory entries */
-static struct dirent *xreaddir(DIR *dp)
-{
-       struct dirent *d;
-
-       assert(dp);
-
-       while ((d = readdir(dp))) {
-               if (!strcmp(d->d_name, ".") ||
-                   !strcmp(d->d_name, ".."))
-                       continue;
-
-               /* blacklist here? */
-               break;
-       }
-       return d;
-}
-
 /* Returns full pat to the device node (TODO: what about sysfs_blkdev_get_path()) */
 static char *get_device_path(struct lsblk_device *dev)
 {