dte test coverage


Directory: ./
File: src/util/xdirent.h
Date: 2024-12-21 16:03:22
Exec Total Coverage
Lines: 15 15 100.0%
Functions: 3 3 100.0%
Branches: 4 8 50.0%

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
9 NONNULL_ARGS WARN_UNUSED_RESULT
10 10 static inline DIR *xopendir(const char *path)
11 {
12 10 DIR *dir;
13 10 do {
14 10 dir = opendir(path);
15
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10 } while (!dir && errno == EINTR);
16 10 return dir;
17 }
18
19 NONNULL_ARGS WARN_UNUSED_RESULT
20 273 static inline struct dirent *xreaddir(DIR *dir)
21 {
22 273 struct dirent *ent;
23 273 do {
24 273 errno = 0;
25 273 ent = readdir(dir);
26
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 263 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
273 } while (!ent && errno == EINTR);
27 273 return ent;
28 }
29
30 NONNULL_ARGS
31 10 static inline int xclosedir(DIR *dir)
32 {
33 // We don't handle EINTR in a similar fashion to xclose() here, because
34 // closedir() frees `dir` and it's typically unnecessary anyway.
35 10 return closedir(dir);
36 }
37
38 #endif
39