summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bftw.c6
-rw-r--r--eval.c6
-rw-r--r--exec.c6
-rw-r--r--util.h4
4 files changed, 7 insertions, 15 deletions
diff --git a/bftw.c b/bftw.c
index 74a9307..e76ca09 100644
--- a/bftw.c
+++ b/bftw.c
@@ -349,11 +349,7 @@ static bool bftw_should_retry(struct bftw_cache *cache, const struct bftw_dir *s
static int bftw_dir_openat(struct bftw_cache *cache, struct bftw_dir *dir, const struct bftw_dir *base, int at_fd, const char *at_path) {
assert(dir->fd < 0);
- int flags = O_RDONLY | O_CLOEXEC;
-#ifdef O_DIRECTORY
- flags |= O_DIRECTORY;
-#endif
-
+ int flags = O_RDONLY | O_CLOEXEC | O_DIRECTORY;
int fd = openat(at_fd, at_path, flags);
if (fd < 0 && bftw_should_retry(cache, base)) {
diff --git a/eval.c b/eval.c
index 16105fe..6883ce4 100644
--- a/eval.c
+++ b/eval.c
@@ -334,11 +334,7 @@ bool eval_empty(const struct expr *expr, struct eval_state *state) {
struct BFTW *ftwbuf = state->ftwbuf;
if (ftwbuf->typeflag == BFTW_DIR) {
- int flags = O_RDONLY | O_CLOEXEC;
-#ifdef O_DIRECTORY
- flags |= O_DIRECTORY;
-#endif
- int dfd = openat(ftwbuf->at_fd, ftwbuf->at_path, flags);
+ int dfd = openat(ftwbuf->at_fd, ftwbuf->at_path, O_RDONLY | O_CLOEXEC | O_DIRECTORY);
if (dfd < 0) {
eval_error(state);
goto done;
diff --git a/exec.c b/exec.c
index 342775c..1884536 100644
--- a/exec.c
+++ b/exec.c
@@ -306,11 +306,7 @@ static int bfs_exec_openwd(struct bfs_exec *execbuf, const struct BFTW *ftwbuf)
}
if (execbuf->wd_fd < 0) {
- int flags = O_RDONLY | O_CLOEXEC;
-#ifdef O_DIRECTORY
- flags |= O_DIRECTORY;
-#endif
- execbuf->wd_fd = open(execbuf->wd_path, flags);
+ execbuf->wd_fd = open(execbuf->wd_path, O_RDONLY | O_CLOEXEC | O_DIRECTORY);
}
if (execbuf->wd_fd < 0) {
diff --git a/util.h b/util.h
index 8f20102..b2025e6 100644
--- a/util.h
+++ b/util.h
@@ -50,6 +50,10 @@
# define S_ISWHT(mode) false
#endif
+#ifndef O_DIRECTORY
+# define O_DIRECTORY 0
+#endif
+
/**
* readdir() wrapper that makes error handling cleaner.
*/