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, _ } {...@@ -19,10 +19,10 @@ fn _errno(rc: usize) enum(c_ushort) { ok, _ } {
19// ssize_t read(int fd, void buf[.count], size_t count);19// ssize_t read(int fd, void buf[.count], size_t count);
20// asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count);20// asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count);
21pub fn read(fd: c_int, buf: []u8) errno.Error!usize {21pub 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);
23 return switch (_errno(r)) {23 return switch (_errno(r)) {
24 .ok => @intCast(r),24 .ok => @intCast(r),
25 _ => |c| errno.errorFromInt(c),25 _ => |c| errno.errorFromInt(@intFromEnum(c)),
26 };26 };
27}27}
2828
...@@ -30,10 +30,10 @@ pub fn read(fd: c_int, buf: []u8) errno.Error!usize {...@@ -30,10 +30,10 @@ pub fn read(fd: c_int, buf: []u8) errno.Error!usize {
30// ssize_t write(int fd, const void buf[.count], size_t count);30// ssize_t write(int fd, const void buf[.count], size_t count);
31// asmlinkage long sys_write(unsigned int fd, const char __user *buf, size_t count);31// asmlinkage long sys_write(unsigned int fd, const char __user *buf, size_t count);
32pub fn write(fd: c_int, buf: []const u8) errno.Error!usize {32pub 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);
34 return switch (_errno(r)) {34 return switch (_errno(r)) {
35 .ok => @intCast(r),35 .ok => @intCast(r),
36 _ => |c| errno.errorFromInt(c),36 _ => |c| errno.errorFromInt(@intFromEnum(c)),
37 };37 };
38}38}
3939
test.zig+9
...@@ -1 +1,10 @@...@@ -1 +1,10 @@
1const std = @import("std");1const 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}