| author | |
| committer | |
| log | 21914c7c01d8d1071034153451414719906167b8 |
| tree | e3707276bf48238119cbd2872faab430d9669434 |
| parent | ff612334fa8af05c42b71f784dff521899026f97 |
Add the Linux syscall wrapper for `tee`.
Migrate the `tee` syscall from musl libc to zig libc.
langref: note `ssize_t` and `isize` are ABI compatible
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31911
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: David Senoner <seda18@rolmail.net>
Co-committed-by: David Senoner <seda18@rolmail.net>5 files changed, 16 insertions(+), 10 deletions(-)
doc/langref.html.in+1-1| ... | ... | @@ -525,7 +525,7 @@ |
| 525 | 525 | </tr> |
| 526 | 526 | <tr> |
| 527 | 527 | <th scope="row">{#syntax#}isize{#endsyntax#}</th> |
| 528 | <td><code class="c">intptr_t</code></td> | |
| 528 | <td><code class="c">intptr_t</code>, <code class="c">ssize_t</code></td> | |
| 529 | 529 | <td>signed pointer sized integer</td> |
| 530 | 530 | </tr> |
| 531 | 531 | <tr> |
lib/c/fcntl.zig+5| ... | ... | @@ -12,6 +12,7 @@ comptime { |
| 12 | 12 | symbol(&fallocateLinux, "fallocate"); |
| 13 | 13 | symbol(&posix_fadviseLinux, "posix_fadvise"); |
| 14 | 14 | symbol(&posix_fallocateLinux, "posix_fallocate"); |
| 15 | symbol(&teeLinux, "tee"); | |
| 15 | 16 | } |
| 16 | 17 | } |
| 17 | 18 | |
| ... | ... | @@ -26,3 +27,7 @@ fn posix_fadviseLinux(fd: c_int, offset: off_t, len: off_t, advice: c_int) callc |
| 26 | 27 | fn posix_fallocateLinux(fd: c_int, offset: off_t, len: off_t) callconv(.c) c_int { |
| 27 | 28 | return errno(linux.fallocate(fd, 0, offset, len)); |
| 28 | 29 | } |
| 30 | ||
| 31 | fn teeLinux(src: c_int, dest: c_int, len: usize, flags: c_uint) callconv(.c) isize { | |
| 32 | return errno(linux.tee(src, dest, len, flags)); | |
| 33 | } |
lib/libc/musl/src/linux/tee.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #define _GNU_SOURCE | |
| 2 | #include <fcntl.h> | |
| 3 | #include "syscall.h" | |
| 4 | ||
| 5 | ssize_t tee(int src, int dest, size_t len, unsigned flags) | |
| 6 | { | |
| 7 | 	return syscall(SYS_tee, src, dest, len, flags); | |
| 8 | } |
lib/std/os/linux.zig+10| ... | ... | @@ -2981,6 +2981,16 @@ pub fn map_shadow_stack(addr: usize, size: usize, flags: u32) usize { |
| 2981 | 2981 | return syscall3(.map_shadow_stack, addr, size, flags); |
| 2982 | 2982 | } |
| 2983 | 2983 | |
| 2984 | pub fn tee(src: fd_t, dest: fd_t, len: usize, flags: u32) usize { | |
| 2985 | return syscall4( | |
| 2986 | .tee, | |
| 2987 | @as(u32, @bitCast(src)), | |
| 2988 | @as(u32, @bitCast(dest)), | |
| 2989 | len, | |
| 2990 | flags, | |
| 2991 | ); | |
| 2992 | } | |
| 2993 | ||
| 2984 | 2994 | pub const Sysinfo = switch (native_abi) { |
| 2985 | 2995 | .gnux32, .muslx32 => extern struct { |
| 2986 | 2996 | /// Seconds since boot |
src/libs/musl.zig-1| ... | ... | @@ -745,7 +745,6 @@ const src_files = [_][]const u8{ |
| 745 | 745 | "musl/src/linux/sync_file_range.c", |
| 746 | 746 | "musl/src/linux/syncfs.c", |
| 747 | 747 | "musl/src/linux/sysinfo.c", |
| 748 | "musl/src/linux/tee.c", | |
| 749 | 748 | "musl/src/linux/timerfd.c", |
| 750 | 749 | "musl/src/linux/unshare.c", |
| 751 | 750 | "musl/src/linux/utimes.c", |