dte test coverage


Directory: ./
File: src/util/xdirent.h
Date: 2026-01-27 12:16:02
Coverage Exec Excl Total
Lines: 100.0% 15 0 15
Functions: 100.0% 3 0 3
Branches: 50.0% 4 0 8

Line Branch Exec Source
1 #ifndef UTIL_XDIRENT_H
2 #define UTIL_XDIRENT_H
3
4 #include <dirent.h>
5 #include <errno.h>
6 #include <sys/types.h>
7 #include "macros.h"
8 #include "maybebool.h"
9
10 NONNULL_ARGS WARN_UNUSED_RESULT
11 10 static inline DIR *xopendir(const char *path)
12 {
13 10 DIR *dir;
14 10 do {
15 10 dir = opendir(path); // NOLINT(*-unsafe-functions)
16
1/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 10 times.
✗ Branch 5 → 3 not taken.
✗ Branch 5 → 6 not taken.
10 } while (!dir && errno == EINTR);
17 10 return dir;
18 }
19
20 NONNULL_ARGS WARN_UNUSED_RESULT
21 312 static inline struct dirent *xreaddir(DIR *dir)
22 {
23 312 struct dirent *ent;
24 312 do {
25 312 errno = 0;
26 312 ent = readdir(dir); // NOLINT(*-unsafe-functions)
27
3/4
✓ Branch 4 → 5 taken 10 times.
✓ Branch 4 → 6 taken 302 times.
✗ Branch 5 → 3 not taken.
✓ Branch 5 → 6 taken 10 times.
312 } while (!ent && errno == EINTR);
28 312 return ent;
29 }
30
31 NONNULL_ARGS
32 10 static inline int xclosedir(DIR *dir)
33 {
34 // We don't handle EINTR in a similar fashion to xclose() here, because
35 // closedir() frees `dir` and it's typically unnecessary anyway.
36 10 return closedir(dir); // NOLINT(*-unsafe-functions)
37 }
38
39 MaybeBool is_dir_or_symlink_to_dir(const struct dirent *ent, int dir_fd) NONNULL_ARGS WARN_UNUSED_RESULT;
40
41 #endif
42