diff options
| author | Karel Zak <kzak@redhat.com> | 2025-10-15 10:30:34 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2025-10-15 10:30:34 +0200 |
| commit | 086f4946eb6a312fb1205997bca03423307e4d0d (patch) | |
| tree | d86c79cd5f92b7eed4b7487d8922db23d709efa5 /include/fileutils.h | |
| parent | 44ae940082e702451976f4c07c6b054ca505eb04 (diff) | |
| download | util-linux-086f4946eb6a312fb1205997bca03423307e4d0d.tar.gz | |
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 <kzak@redhat.com>
Diffstat (limited to 'include/fileutils.h')
| -rw-r--r-- | include/fileutils.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/include/fileutils.h b/include/fileutils.h index 672f1c9854..d6a15fd0ba 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 */ |
