From cf9230659e8d64e95209a4d57cbda8a474049ddb Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 17 May 2024 16:10:00 -0400 Subject: Cast AT_FDCWD to int for comparisons Some platforms define AT_FDCWD to a constant like 0xFFFAFDCD that gets typed as an unsigned int. --- src/bftw.c | 6 +++--- src/color.c | 2 +- src/eval.c | 2 +- src/exec.c | 2 +- src/fsade.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/bftw.c b/src/bftw.c index c4d3c17..5322181 100644 --- a/src/bftw.c +++ b/src/bftw.c @@ -1281,7 +1281,7 @@ static int bftw_pin_parent(struct bftw_state *state, struct bftw_file *file) { int fd = parent->fd; if (fd < 0) { - bfs_static_assert(AT_FDCWD != -1); + bfs_static_assert((int)AT_FDCWD != -1); return -1; } @@ -1298,7 +1298,7 @@ static int bftw_ioq_opendir(struct bftw_state *state, struct bftw_file *file) { } int dfd = bftw_pin_parent(state, file); - if (dfd < 0 && dfd != AT_FDCWD) { + if (dfd < 0 && dfd != (int)AT_FDCWD) { goto fail; } @@ -1450,7 +1450,7 @@ static int bftw_ioq_stat(struct bftw_state *state, struct bftw_file *file) { } int dfd = bftw_pin_parent(state, file); - if (dfd < 0 && dfd != AT_FDCWD) { + if (dfd < 0 && dfd != (int)AT_FDCWD) { goto fail; } diff --git a/src/color.c b/src/color.c index 326291d..a0e553f 100644 --- a/src/color.c +++ b/src/color.c @@ -976,7 +976,7 @@ static ssize_t first_broken_offset(const char *path, const struct BFTW *ftwbuf, } else { // We're in print_link_target(), so resolve relative to the link's parent directory at_fd = ftwbuf->at_fd; - if (at_fd == AT_FDCWD && path[0] != '/') { + if (at_fd == (int)AT_FDCWD && path[0] != '/') { at_path = dstrndup(ftwbuf->path, ftwbuf->nameoff); if (at_path && dstrncat(&at_path, path, max) != 0) { ret = -1; diff --git a/src/eval.c b/src/eval.c index 49028b7..4fcda60 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1270,7 +1270,7 @@ static void debug_stat(const struct bfs_ctx *ctx, const struct BFTW *ftwbuf, enu bfs_debug_prefix(ctx, DEBUG_STAT); fprintf(stderr, "bfs_stat("); - if (ftwbuf->at_fd == AT_FDCWD) { + if (ftwbuf->at_fd == (int)AT_FDCWD) { fprintf(stderr, "AT_FDCWD"); } else { size_t baselen = strlen(ftwbuf->path) - strlen(ftwbuf->at_path); diff --git a/src/exec.c b/src/exec.c index 15b3c79..cd73d6c 100644 --- a/src/exec.c +++ b/src/exec.c @@ -268,7 +268,7 @@ static int bfs_exec_openwd(struct bfs_exec *execbuf, const struct BFTW *ftwbuf) bfs_assert(execbuf->wd_fd < 0); bfs_assert(!execbuf->wd_path); - if (ftwbuf->at_fd != AT_FDCWD) { + if (ftwbuf->at_fd != (int)AT_FDCWD) { // Rely on at_fd being the immediate parent bfs_assert(xbaseoff(ftwbuf->at_path) == 0); diff --git a/src/fsade.c b/src/fsade.c index d56fb07..7310141 100644 --- a/src/fsade.c +++ b/src/fsade.c @@ -41,7 +41,7 @@ static const char *fake_at(const struct BFTW *ftwbuf) { static atomic int proc_works = -1; dchar *path = NULL; - if (ftwbuf->at_fd == AT_FDCWD || load(&proc_works, relaxed) == 0) { + if (ftwbuf->at_fd == (int)AT_FDCWD || load(&proc_works, relaxed) == 0) { goto fail; } -- cgit v1.2.3