all: fix build with musl libc

- Should not assume whether O_xxx macros are defined by checking
  feature test macros.
- Workaround conflicting getdents() declaration.
This commit is contained in:
CismonX 2025-02-16 00:19:51 +08:00
parent 1db61bc878
commit c90c5f6fc7
No known key found for this signature in database
GPG key ID: 3094873E29A482FB
4 changed files with 12 additions and 7 deletions

View file

@ -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__

View file

@ -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().

View file

@ -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

View file

@ -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;