| 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); // NOLINT(*-unsafe-functions) | |
| 15 |
1/4✗ Branch 0 (4→5) not taken.
✓ Branch 1 (4→6) taken 10 times.
✗ Branch 2 (5→3) not taken.
✗ Branch 3 (5→6) not taken.
|
10 | } while (!dir && errno == EINTR); |
| 16 | 10 | return dir; | |
| 17 | } | ||
| 18 | |||
| 19 | NONNULL_ARGS WARN_UNUSED_RESULT | ||
| 20 | 306 | static inline struct dirent *xreaddir(DIR *dir) | |
| 21 | { | ||
| 22 | 306 | struct dirent *ent; | |
| 23 | 306 | do { | |
| 24 | 306 | errno = 0; | |
| 25 | 306 | ent = readdir(dir); // NOLINT(*-unsafe-functions) | |
| 26 |
3/4✓ Branch 0 (4→5) taken 10 times.
✓ Branch 1 (4→6) taken 296 times.
✗ Branch 2 (5→3) not taken.
✓ Branch 3 (5→6) taken 10 times.
|
306 | } while (!ent && errno == EINTR); |
| 27 | 306 | 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); // NOLINT(*-unsafe-functions) | |
| 36 | } | ||
| 37 | |||
| 38 | #endif | ||
| 39 |