]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/fileutils: add is_dotdir_dirent()
authorKarel Zak <kzak@redhat.com>
Wed, 15 Oct 2025 08:30:34 +0000 (10:30 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 15 Oct 2025 08:30:34 +0000 (10:30 +0200)
This code pattern is repeated on many places, let's move it to
simple inline function.

Signed-off-by: Karel Zak <kzak@redhat.com>
include/fileutils.h

index 672f1c9854d34805fa9479462314b226a2b0c0ef..d6a15fd0ba23941821f13910d58f13f8d0ff30d9 100644 (file)
@@ -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 */