From: Karel Zak Date: Wed, 15 Oct 2025 08:30:34 +0000 (+0200) Subject: lib/fileutils: add is_dotdir_dirent() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=086f4946eb6a312fb1205997bca03423307e4d0d;p=thirdparty%2Futil-linux.git 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 --- 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 */