authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-04-20 02:39:02 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-04-20 02:39:02 -07:00
log1ba3539deaae8fe68b28e93dc533ef2d6653a9ad
tree0a2b35d4533c34a7c414cca5de5305531fb22262
parent62e135f2d06d249255ad8c387ca9f8fcae1a2e7c

add tests


2 files changed, 13 insertions(+), 4 deletions(-)

mod.zig+4-4
......@@ -19,10 +19,10 @@ fn _errno(rc: usize) enum(c_ushort) { ok, _ } {
1919// ssize_t read(int fd, void buf[.count], size_t count);
2020// asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count);
2121pub fn read(fd: c_int, buf: []u8) errno.Error!usize {
22 const r = syscall3(.read, fd, buf.ptr, buf.len);
22 const r = syscall3(.read, @intCast(fd), @intFromPtr(buf.ptr), buf.len);
2323 return switch (_errno(r)) {
2424 .ok => @intCast(r),
25 _ => |c| errno.errorFromInt(c),
25 _ => |c| errno.errorFromInt(@intFromEnum(c)),
2626 };
2727}
2828
......@@ -30,10 +30,10 @@ pub fn read(fd: c_int, buf: []u8) errno.Error!usize {
3030// ssize_t write(int fd, const void buf[.count], size_t count);
3131// asmlinkage long sys_write(unsigned int fd, const char __user *buf, size_t count);
3232pub fn write(fd: c_int, buf: []const u8) errno.Error!usize {
33 const r = syscall3(.write, fd, buf.ptr, buf.len);
33 const r = syscall3(.write, @intCast(fd), @intFromPtr(buf.ptr), buf.len);
3434 return switch (_errno(r)) {
3535 .ok => @intCast(r),
36 _ => |c| errno.errorFromInt(c),
36 _ => |c| errno.errorFromInt(@intFromEnum(c)),
3737 };
3838}
3939
test.zig+9
......@@ -1 +1,10 @@
11const std = @import("std");
2const builtin = @import("builtin");
3const linux = @import("sys-linux");
4
5test {
6 if (builtin.target.os.tag != .linux) return;
7 if (builtin.target.cpu.arch != .x86_64) return;
8 _ = &linux.read;
9 _ = &linux.write;
10}