mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
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
This commit is contained in:
committed by
Andrew Kelley
parent
50cc3b91a5
commit
aaba36ff76
@@ -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");
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
-16
@@ -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
|
||||
}
|
||||
-8
@@ -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));
|
||||
}
|
||||
Vendored
-9
@@ -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));
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user