]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/dirent-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include "dirent-util.h"
8 #include "string-util.h"
10 int dirent_ensure_type(DIR *d
, struct dirent
*de
) {
16 if (de
->d_type
!= DT_UNKNOWN
)
19 if (fstatat(dirfd(d
), de
->d_name
, &st
, AT_SYMLINK_NOFOLLOW
) < 0)
23 S_ISREG(st
.st_mode
) ? DT_REG
:
24 S_ISDIR(st
.st_mode
) ? DT_DIR
:
25 S_ISLNK(st
.st_mode
) ? DT_LNK
:
26 S_ISFIFO(st
.st_mode
) ? DT_FIFO
:
27 S_ISSOCK(st
.st_mode
) ? DT_SOCK
:
28 S_ISCHR(st
.st_mode
) ? DT_CHR
:
29 S_ISBLK(st
.st_mode
) ? DT_BLK
:
35 bool dirent_is_file(const struct dirent
*de
) {
38 if (!IN_SET(de
->d_type
, DT_REG
, DT_LNK
, DT_UNKNOWN
))
41 if (hidden_or_backup_file(de
->d_name
))
47 bool dirent_is_file_with_suffix(const struct dirent
*de
, const char *suffix
) {
50 if (!IN_SET(de
->d_type
, DT_REG
, DT_LNK
, DT_UNKNOWN
))
53 if (de
->d_name
[0] == '.')
59 return endswith(de
->d_name
, suffix
);
62 struct dirent
* readdir_no_dot(DIR *dirp
) {
67 if (d
&& dot_or_dot_dot(d
->d_name
))