From 086f4946eb6a312fb1205997bca03423307e4d0d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 15 Oct 2025 10:30:34 +0200 Subject: [PATCH] lib/fileutils: add is_dotdir_dirent() This code pattern is repeated on many places, let's move it to simple inline function. Signed-off-by: Karel Zak --- include/fileutils.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/fileutils.h b/include/fileutils.h index 672f1c985..d6a15fd0b 100644 --- a/include/fileutils.h +++ b/include/fileutils.h @@ -119,4 +119,12 @@ extern char *ul_restricted_path_oper(const char *path, int (*oper)(const char *path, char **result, void *data), void *data); +/* return 1 if @d is "." or ".." */ +static inline bool is_dotdir_dirent(const struct dirent *d) +{ + return (d && d->d_name[0] == '.' + && (d->d_name[1] == 0 + || (d->d_name[1] == '.' && d->d_name[2] == 0))); +} + #endif /* UTIL_LINUX_FILEUTILS */ -- 2.47.3