diff options
author | Karel Zak | 2019-04-11 13:11:53 +0200 |
---|---|---|
committer | Karel Zak | 2019-04-11 13:11:53 +0200 |
commit | 7761bd3bb6c56a375ad8d027c20d020aaa33e2d8 (patch) | |
tree | 1c5a07da00a32e8b6dbde0eef1500f48ef340af2 /include | |
parent | setarch: add new e2k subarches (diff) | |
download | kernel-qcow2-util-linux-7761bd3bb6c56a375ad8d027c20d020aaa33e2d8.tar.gz kernel-qcow2-util-linux-7761bd3bb6c56a375ad8d027c20d020aaa33e2d8.tar.xz kernel-qcow2-util-linux-7761bd3bb6c56a375ad8d027c20d020aaa33e2d8.zip |
lib/fileutils: add xreaddir()
Remove duplicate code and keep only one implementation in
include/fileutils.h.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/fileutils.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/include/fileutils.h b/include/fileutils.h index 8a7e66261..043f2ca44 100644 --- a/include/fileutils.h +++ b/include/fileutils.h @@ -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 */ |