From 1ba3539deaae8fe68b28e93dc533ef2d6653a9ad Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 20 Apr 2025 02:39:02 -0700 Subject: [PATCH] add tests --- mod.zig | 8 ++++---- test.zig | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mod.zig b/mod.zig index 2e8ac3a287a4eab65b5b79dfd063954ed56ed626..927355ec8d3f971f88886196432d13949db5e92c 100644 --- a/mod.zig +++ b/mod.zig @@ -19,10 +19,10 @@ fn _errno(rc: usize) enum(c_ushort) { ok, _ } { // ssize_t read(int fd, void buf[.count], size_t count); // asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count); pub fn read(fd: c_int, buf: []u8) errno.Error!usize { - const r = syscall3(.read, fd, buf.ptr, buf.len); + const r = syscall3(.read, @intCast(fd), @intFromPtr(buf.ptr), buf.len); return switch (_errno(r)) { .ok => @intCast(r), - _ => |c| errno.errorFromInt(c), + _ => |c| errno.errorFromInt(@intFromEnum(c)), }; } @@ -30,10 +30,10 @@ pub fn read(fd: c_int, buf: []u8) errno.Error!usize { // ssize_t write(int fd, const void buf[.count], size_t count); // asmlinkage long sys_write(unsigned int fd, const char __user *buf, size_t count); pub fn write(fd: c_int, buf: []const u8) errno.Error!usize { - const r = syscall3(.write, fd, buf.ptr, buf.len); + const r = syscall3(.write, @intCast(fd), @intFromPtr(buf.ptr), buf.len); return switch (_errno(r)) { .ok => @intCast(r), - _ => |c| errno.errorFromInt(c), + _ => |c| errno.errorFromInt(@intFromEnum(c)), }; } diff --git a/test.zig b/test.zig index 95a0b682a71942e4010a9c8ee96461fb9a3b53a3..a0ba83ba722bd28a1a4484f6b19ebd986fe63ba8 100644 --- a/test.zig +++ b/test.zig @@ -1 +1,10 @@ const std = @import("std"); +const builtin = @import("builtin"); +const linux = @import("sys-linux"); + +test { + if (builtin.target.os.tag != .linux) return; + if (builtin.target.cpu.arch != .x86_64) return; + _ = &linux.read; + _ = &linux.write; +} -- 2.54.0