1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010-2012 Lennart Poettering
11 #include "dirent-util.h"
12 #include "path-util.h"
13 #include "string-util.h"
15 int dirent_ensure_type(DIR *d, struct dirent *de) {
21 if (de->d_type != DT_UNKNOWN)
24 if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0)
28 S_ISREG(st.st_mode) ? DT_REG :
29 S_ISDIR(st.st_mode) ? DT_DIR :
30 S_ISLNK(st.st_mode) ? DT_LNK :
31 S_ISFIFO(st.st_mode) ? DT_FIFO :
32 S_ISSOCK(st.st_mode) ? DT_SOCK :
33 S_ISCHR(st.st_mode) ? DT_CHR :
34 S_ISBLK(st.st_mode) ? DT_BLK :
40 bool dirent_is_file(const struct dirent *de) {
43 if (!IN_SET(de->d_type, DT_REG, DT_LNK, DT_UNKNOWN))
46 if (hidden_or_backup_file(de->d_name))
52 bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) {
55 if (!IN_SET(de->d_type, DT_REG, DT_LNK, DT_UNKNOWN))
58 if (de->d_name[0] == '.')
64 return endswith(de->d_name, suffix);
67 struct dirent* readdir_no_dot(DIR *dirp) {
72 if (d && dot_or_dot_dot(d->d_name))