From c90c5f6fc771e21b47adad25f0fd5efdc03a7002 Mon Sep 17 00:00:00 2001 From: CismonX Date: Sun, 16 Feb 2025 00:19:51 +0800 Subject: [PATCH] all: fix build with musl libc - Should not assume whether O_xxx macros are defined by checking feature test macros. - Workaround conflicting getdents() declaration. --- src/defs.h | 3 --- src/fs_ops.c | 2 ++ src/fsck_online.c | 7 +++++-- src/watcher.c | 7 +++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/defs.h b/src/defs.h index 194c841..c5a2052 100644 --- a/src/defs.h +++ b/src/defs.h @@ -97,9 +97,6 @@ #if defined(__FreeBSD__) || (defined(__linux__) && defined(_GNU_SOURCE)) # define HAVE_PIPE2 1 -#else -# define O_DIRECT 0 -# define O_PATH 0 // FreeBSD supports O_PATH since 13.1 #endif #ifndef __FreeBSD__ diff --git a/src/fs_ops.c b/src/fs_ops.c index eb0dfc4..dc83310 100644 --- a/src/fs_ops.c +++ b/src/fs_ops.c @@ -794,9 +794,11 @@ bm_open ( } } +#ifdef O_DIRECT if (flags & O_DIRECT) { fi->direct_io = 1; } +#endif #ifndef __FreeBSD__ // Cannot reliably keep cache on FreeBSD, we're unable to explicitly // flush it. See comments for inval_inode(). diff --git a/src/fsck_online.c b/src/fsck_online.c index fd95ba3..6d11cb1 100644 --- a/src/fsck_online.c +++ b/src/fsck_online.c @@ -68,7 +68,7 @@ struct fsck_dir { // Forward declaration start #ifdef __linux__ -static ssize_t getdents (int, void *, size_t); +static ssize_t getdents_ (int, void *, size_t); #endif static int next_subdir (struct fsck_ctx *, struct fsck_dir *, @@ -81,8 +81,11 @@ static void print_version (void); #ifdef __linux__ +// Some libc (e.g., musl) may declare a getdents() function +// in dirent.h with conflicting types. +#define getdents getdents_ static ssize_t -getdents ( +getdents_ ( int dirfd, void *buf, size_t bufsize diff --git a/src/watcher.c b/src/watcher.c index 5437385..ecd5f99 100644 --- a/src/watcher.c +++ b/src/watcher.c @@ -158,8 +158,11 @@ impl_rearm ( } #elif defined(WATCHER_IMPL_KQUEUE) - int wfd = openat(w->dirfd, w->name, - O_RDONLY | O_CLOEXEC | O_PATH | O_RESOLVE_BENEATH); + int open_flags = O_RDONLY | O_CLOEXEC | O_RESOLVE_BENEATH; +#ifdef O_PATH + open_flags |= O_PATH; +#endif + int wfd = openat(w->dirfd, w->name, open_flags); if (wfd < 0) { log_printf("openat(): %s", xstrerror(errno)); return -1;