]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/dirent-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2010-2012 Lennart Poettering
9 #include "dirent-util.h"
10 #include "path-util.h"
11 #include "string-util.h"
13 int dirent_ensure_type(DIR *d
, struct dirent
*de
) {
19 if (de
->d_type
!= DT_UNKNOWN
)
22 if (fstatat(dirfd(d
), de
->d_name
, &st
, AT_SYMLINK_NOFOLLOW
) < 0)
26 S_ISREG(st
.st_mode
) ? DT_REG
:
27 S_ISDIR(st
.st_mode
) ? DT_DIR
:
28 S_ISLNK(st
.st_mode
) ? DT_LNK
:
29 S_ISFIFO(st
.st_mode
) ? DT_FIFO
:
30 S_ISSOCK(st
.st_mode
) ? DT_SOCK
:
31 S_ISCHR(st
.st_mode
) ? DT_CHR
:
32 S_ISBLK(st
.st_mode
) ? DT_BLK
:
38 bool dirent_is_file(const struct dirent
*de
) {
41 if (!IN_SET(de
->d_type
, DT_REG
, DT_LNK
, DT_UNKNOWN
))
44 if (hidden_or_backup_file(de
->d_name
))
50 bool dirent_is_file_with_suffix(const struct dirent
*de
, const char *suffix
) {
53 if (!IN_SET(de
->d_type
, DT_REG
, DT_LNK
, DT_UNKNOWN
))
56 if (de
->d_name
[0] == '.')
62 return endswith(de
->d_name
, suffix
);
65 struct dirent
* readdir_no_dot(DIR *dirp
) {
70 if (d
&& dot_or_dot_dot(d
->d_name
))