From 41d1c3d53babe8d7e6bc135ddaa6c6a2b8ef37fa Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 18 Feb 2026 16:36:26 -0800 Subject: [PATCH] add writev --- mod.zig | 10 ++++++++++ test.zig | 1 + 2 files changed, 11 insertions(+) diff --git a/mod.zig b/mod.zig index a54977acc8e65137e271a0c0945b564b009972c1..bdb9ec0a0508c1ba4c5947730a625f407a9a8dfd 100644 --- a/mod.zig +++ b/mod.zig @@ -2622,6 +2622,10 @@ pub const libc = struct { /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/write.html pub extern fn write(fd: c_int, buf: *const anyopaque, n: usize) isize; + /// ssize_t writev(int fildes, const struct iovec *iov, int iovcnt); + /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/writev.html + pub extern fn writev(fd: c_int, iovec: [*]const struct_iovec, count: c_int) isize; + /// double y0(double x); /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/y0.html pub extern fn y0(x: f64) f64; @@ -3157,3 +3161,9 @@ pub fn write(fd: c_int, buf: []const u8) !usize { std.debug.assert(rc >= 0); return @intCast(rc); } +pub fn writev(fd: c_int, iovec: []const struct_iovec) !usize { + const rc = libc.writev(fd, iovec.ptr, @intCast(iovec.len)); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc >= 0); + return @intCast(rc); +} diff --git a/test.zig b/test.zig index 87d169144197e1d0d9939f020533fb565137ebc7..9c748abb6eea4fd26ff79649d88b64c82eb0ee5c 100644 --- a/test.zig +++ b/test.zig @@ -31,4 +31,5 @@ test { _ = &linux.memfd_create; _ = &linux.readlinkat; _ = &linux.write; + _ = &linux.writev; } -- 2.54.0