From 2f4616052da1e59ed4e88b61d246714ea79b09b5 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 24 Aug 2026 12:24:03 -0700 Subject: [PATCH] add support for freebsd, netbsd, openbsd --- licenses.txt | 3 +++ net.zig | 31 +++++++++++++++++++++++-------- zigmod.yml | 3 +++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/licenses.txt b/licenses.txt index b6f1b2d6c00fb5a9d7ab51684c19a7ebdcb163a5..b7a3d8d90907857d5355469d1d9c3181a55afdd6 100644 --- a/licenses.txt +++ b/licenses.txt @@ -11,6 +11,9 @@ MIT: - git https://github.com/nektro/zig-expect - git https://github.com/nektro/zig-extras - git https://github.com/nektro/zig-sys-darwin +- git https://github.com/nektro/zig-sys-freebsd - git https://github.com/nektro/zig-sys-linux +- git https://github.com/nektro/zig-sys-netbsd +- git https://github.com/nektro/zig-sys-openbsd - git https://github.com/nektro/zig-time - git https://github.com/nektro/zig-unicode-ucd diff --git a/net.zig b/net.zig index f7f5c5ff12cc1804dd850342eb33760d91fdfd4b..d9ef291318dfbad5420fbb165fe6754450a2c46d 100644 --- a/net.zig +++ b/net.zig @@ -10,6 +10,9 @@ const os = builtin.target.os.tag; const sys = switch (os) { .linux => sys_linux, + .freebsd => @import("sys-freebsd"), + .netbsd => @import("sys-netbsd"), + .openbsd => @import("sys-openbsd"), else => @compileError("TODO"), }; @@ -164,6 +167,9 @@ pub const Ip6Address = extern struct { pub const Socket = switch (os) { .linux => enum(c_uint) { _ }, + .freebsd => enum(c_uint) { _ }, + .netbsd => enum(c_uint) { _ }, + .openbsd => enum(c_uint) { _ }, else => @compileError("TODO"), }; @@ -180,6 +186,21 @@ pub const Stream = struct { } pub fn sendfile(s: Stream, file: nfs.File, offset: off_t, count: ?usize) !void { + switch (os) { + .freebsd, + .netbsd, + .openbsd, + => { + const count_actual = count orelse (try file.stat()).size; + const region = try file.mmapRegion(offset, count_actual); + defer nfs.munmap(region); + try s.writeAll(region); + return; + }, + .linux, + => {}, + else => comptime unreachable, + } const count_actual = count orelse (try file.stat()).size; var total: u63 = 0; while (total < count_actual) { @@ -204,10 +225,7 @@ pub const Stream = struct { pub const readInt = R.readInt; pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; - pub const ReadError = switch (builtin.target.os.tag) { - .linux => sys.errno.Error, - else => @compileError("TODO"), - }; + pub const ReadError = sys.errno.Error; pub fn read(s: Stream, buffer: []u8) ReadError!usize { return sys.recv(@intFromEnum(s.socket), buffer, 0); } @@ -234,10 +252,7 @@ pub const Stream = struct { pub const writeIntPretty = W.writeIntPretty; pub const print = W.print; - pub const WriteError = switch (builtin.target.os.tag) { - .linux => sys.errno.Error, - else => @compileError("TODO"), - }; + pub const WriteError = sys.errno.Error; pub fn write(s: Stream, bytes: []const u8) WriteError!usize { return sys.send(@intFromEnum(s.socket), bytes, 0); } diff --git a/zigmod.yml b/zigmod.yml index 1a87a86268e26e966c434277b9dee0966025bf81..a39dd27a6fabc2831d53b1960c9feaf012f7071d 100644 --- a/zigmod.yml +++ b/zigmod.yml @@ -9,5 +9,8 @@ dependencies: - src: git https://github.com/nektro/zig-nfs - src: git https://github.com/nektro/zig-time - src: git https://github.com/nektro/zig-whatwg-url + - src: git https://github.com/nektro/zig-sys-freebsd + - src: git https://github.com/nektro/zig-sys-netbsd + - src: git https://github.com/nektro/zig-sys-openbsd root_dependencies: - src: git https://github.com/nektro/zig-expect -- 2.54.0