authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-24 12:24:03-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-24 12:24:03-07:00
log2f4616052da1e59ed4e88b61d246714ea79b09b5
tree65ccfea35c38ed0dc96c65dcbc09335608361f72
parenta8e08374032bdaea573515f9c839560000503b8f
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add support for freebsd, netbsd, openbsd


3 files changed, 29 insertions(+), 8 deletions(-)

licenses.txt+3
......@@ -11,6 +11,9 @@ MIT:
1111- git https://github.com/nektro/zig-expect
1212- git https://github.com/nektro/zig-extras
1313- git https://github.com/nektro/zig-sys-darwin
14- git https://github.com/nektro/zig-sys-freebsd
1415- git https://github.com/nektro/zig-sys-linux
16- git https://github.com/nektro/zig-sys-netbsd
17- git https://github.com/nektro/zig-sys-openbsd
1518- git https://github.com/nektro/zig-time
1619- git https://github.com/nektro/zig-unicode-ucd
net.zig+23-8
......@@ -10,6 +10,9 @@ const os = builtin.target.os.tag;
1010
1111const sys = switch (os) {
1212 .linux => sys_linux,
13 .freebsd => @import("sys-freebsd"),
14 .netbsd => @import("sys-netbsd"),
15 .openbsd => @import("sys-openbsd"),
1316 else => @compileError("TODO"),
1417};
1518
......@@ -164,6 +167,9 @@ pub const Ip6Address = extern struct {
164167
165168pub const Socket = switch (os) {
166169 .linux => enum(c_uint) { _ },
170 .freebsd => enum(c_uint) { _ },
171 .netbsd => enum(c_uint) { _ },
172 .openbsd => enum(c_uint) { _ },
167173 else => @compileError("TODO"),
168174};
169175
......@@ -180,6 +186,21 @@ pub const Stream = struct {
180186 }
181187
182188 pub fn sendfile(s: Stream, file: nfs.File, offset: off_t, count: ?usize) !void {
189 switch (os) {
190 .freebsd,
191 .netbsd,
192 .openbsd,
193 => {
194 const count_actual = count orelse (try file.stat()).size;
195 const region = try file.mmapRegion(offset, count_actual);
196 defer nfs.munmap(region);
197 try s.writeAll(region);
198 return;
199 },
200 .linux,
201 => {},
202 else => comptime unreachable,
203 }
183204 const count_actual = count orelse (try file.stat()).size;
184205 var total: u63 = 0;
185206 while (total < count_actual) {
......@@ -204,10 +225,7 @@ pub const Stream = struct {
204225 pub const readInt = R.readInt;
205226 pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc;
206227
207 pub const ReadError = switch (builtin.target.os.tag) {
208 .linux => sys.errno.Error,
209 else => @compileError("TODO"),
210 };
228 pub const ReadError = sys.errno.Error;
211229 pub fn read(s: Stream, buffer: []u8) ReadError!usize {
212230 return sys.recv(@intFromEnum(s.socket), buffer, 0);
213231 }
......@@ -234,10 +252,7 @@ pub const Stream = struct {
234252 pub const writeIntPretty = W.writeIntPretty;
235253 pub const print = W.print;
236254
237 pub const WriteError = switch (builtin.target.os.tag) {
238 .linux => sys.errno.Error,
239 else => @compileError("TODO"),
240 };
255 pub const WriteError = sys.errno.Error;
241256 pub fn write(s: Stream, bytes: []const u8) WriteError!usize {
242257 return sys.send(@intFromEnum(s.socket), bytes, 0);
243258 }
zigmod.yml+3
......@@ -9,5 +9,8 @@ dependencies:
99 - src: git https://github.com/nektro/zig-nfs
1010 - src: git https://github.com/nektro/zig-time
1111 - src: git https://github.com/nektro/zig-whatwg-url
12 - src: git https://github.com/nektro/zig-sys-freebsd
13 - src: git https://github.com/nektro/zig-sys-netbsd
14 - src: git https://github.com/nektro/zig-sys-openbsd
1215root_dependencies:
1316 - src: git https://github.com/nektro/zig-expect