commit aaba36ff763a7f016bba1afc4eff758302538362 (tree)
parent 50cc3b91a5b325b645b0c5c81f3401600b15c92a
Author: Josh Megnauth <jo.sh@tutanota.com>
Date: Fri, 13 Mar 2026 19:37:06 -0400
libzigc: posix_{fadvise, fallocate}, fallocate
This commit removes `posix_fadvise`, `posix_fallocate`, and `fallocate`
from the bundled musl by forwarding to Zig's wrappers. `musl`'s
implemenation does not use `__syscall_cp`, so I assume trivially
replacing these functions is okay.
For `posix_fadvise`, `musl` notes that the arguments are reordered
for ARM and other architectures. Zig's wrapper already handles this
case.
Contributes toward: #30978
Diffstat:
6 files changed, 29 insertions(+), 36 deletions(-)
diff --git a/lib/c.zig b/lib/c.zig
@@ -63,6 +63,7 @@ pub fn errno(syscall_return_value: usize) c_int {
comptime {
_ = @import("c/ctype.zig");
+ _ = @import("c/fcntl.zig");
_ = @import("c/inttypes.zig");
if (!builtin.target.isMinGW()) {
_ = @import("c/malloc.zig");
diff --git a/lib/c/fcntl.zig b/lib/c/fcntl.zig
@@ -0,0 +1,28 @@
+const builtin = @import("builtin");
+
+const std = @import("std");
+const linux = std.os.linux;
+const off_t = linux.off_t;
+
+const symbol = @import("../c.zig").symbol;
+const errno = @import("../c.zig").errno;
+
+comptime {
+ if (builtin.target.isMuslLibC()) {
+ symbol(&fallocateLinux, "fallocate");
+ symbol(&posix_fadviseLinux, "posix_fadvise");
+ symbol(&posix_fallocateLinux, "posix_fallocate");
+ }
+}
+
+fn fallocateLinux(fd: c_int, mode: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
+ return errno(linux.fallocate(fd, mode, offset, len));
+}
+
+fn posix_fadviseLinux(fd: c_int, offset: off_t, len: off_t, advice: c_int) callconv(.c) c_int {
+ return errno(linux.fadvise(fd, offset, len, @intCast(advice)));
+}
+
+fn posix_fallocateLinux(fd: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
+ return errno(linux.fallocate(fd, 0, offset, len));
+}
diff --git a/lib/libc/musl/src/fcntl/posix_fadvise.c b/lib/libc/musl/src/fcntl/posix_fadvise.c
@@ -1,16 +0,0 @@
-#include <fcntl.h>
-#include "syscall.h"
-
-int posix_fadvise(int fd, off_t base, off_t len, int advice)
-{
-#if defined(SYSCALL_FADVISE_6_ARG)
- /* Some archs, at least arm and powerpc, have the syscall
- * arguments reordered to avoid needing 7 argument registers
- * due to 64-bit argument alignment. */
- return -__syscall(SYS_fadvise, fd, advice,
- __SYSCALL_LL_E(base), __SYSCALL_LL_E(len));
-#else
- return -__syscall(SYS_fadvise, fd, __SYSCALL_LL_O(base),
- __SYSCALL_LL_E(len), advice);
-#endif
-}
diff --git a/lib/libc/musl/src/fcntl/posix_fallocate.c b/lib/libc/musl/src/fcntl/posix_fallocate.c
@@ -1,8 +0,0 @@
-#include <fcntl.h>
-#include "syscall.h"
-
-int posix_fallocate(int fd, off_t base, off_t len)
-{
- return -__syscall(SYS_fallocate, fd, 0, __SYSCALL_LL_E(base),
- __SYSCALL_LL_E(len));
-}
diff --git a/lib/libc/musl/src/linux/fallocate.c b/lib/libc/musl/src/linux/fallocate.c
@@ -1,9 +0,0 @@
-#define _GNU_SOURCE
-#include <fcntl.h>
-#include "syscall.h"
-
-int fallocate(int fd, int mode, off_t base, off_t len)
-{
- return syscall(SYS_fallocate, fd, mode, __SYSCALL_LL_E(base),
- __SYSCALL_LL_E(len));
-}
diff --git a/src/libs/musl.zig b/src/libs/musl.zig
@@ -589,8 +589,6 @@ const src_files = [_][]const u8{
"musl/src/fcntl/fcntl.c",
"musl/src/fcntl/openat.c",
"musl/src/fcntl/open.c",
- "musl/src/fcntl/posix_fadvise.c",
- "musl/src/fcntl/posix_fallocate.c",
"musl/src/fenv/aarch64/fenv.s",
"musl/src/fenv/arm/fenv.c",
"musl/src/fenv/arm/fenv-hf.S",
@@ -708,7 +706,6 @@ const src_files = [_][]const u8{
"musl/src/linux/copy_file_range.c",
"musl/src/linux/epoll.c",
"musl/src/linux/eventfd.c",
- "musl/src/linux/fallocate.c",
"musl/src/linux/fanotify.c",
"musl/src/linux/getdents.c",
"musl/src/linux/getrandom.c",