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:...@@ -11,6 +11,9 @@ MIT:
11- git https://github.com/nektro/zig-expect11- git https://github.com/nektro/zig-expect
12- git https://github.com/nektro/zig-extras12- git https://github.com/nektro/zig-extras
13- git https://github.com/nektro/zig-sys-darwin13- git https://github.com/nektro/zig-sys-darwin
14- git https://github.com/nektro/zig-sys-freebsd
14- git https://github.com/nektro/zig-sys-linux15- 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
15- git https://github.com/nektro/zig-time18- git https://github.com/nektro/zig-time
16- git https://github.com/nektro/zig-unicode-ucd19- git https://github.com/nektro/zig-unicode-ucd
net.zig+23-8
...@@ -10,6 +10,9 @@ const os = builtin.target.os.tag;...@@ -10,6 +10,9 @@ const os = builtin.target.os.tag;
1010
11const sys = switch (os) {11const sys = switch (os) {
12 .linux => sys_linux,12 .linux => sys_linux,
13 .freebsd => @import("sys-freebsd"),
14 .netbsd => @import("sys-netbsd"),
15 .openbsd => @import("sys-openbsd"),
13 else => @compileError("TODO"),16 else => @compileError("TODO"),
14};17};
1518
...@@ -164,6 +167,9 @@ pub const Ip6Address = extern struct {...@@ -164,6 +167,9 @@ pub const Ip6Address = extern struct {
164167
165pub const Socket = switch (os) {168pub const Socket = switch (os) {
166 .linux => enum(c_uint) { _ },169 .linux => enum(c_uint) { _ },
170 .freebsd => enum(c_uint) { _ },
171 .netbsd => enum(c_uint) { _ },
172 .openbsd => enum(c_uint) { _ },
167 else => @compileError("TODO"),173 else => @compileError("TODO"),
168};174};
169175
...@@ -180,6 +186,21 @@ pub const Stream = struct {...@@ -180,6 +186,21 @@ pub const Stream = struct {
180 }186 }
181187
182 pub fn sendfile(s: Stream, file: nfs.File, offset: off_t, count: ?usize) !void {188 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 }
183 const count_actual = count orelse (try file.stat()).size;204 const count_actual = count orelse (try file.stat()).size;
184 var total: u63 = 0;205 var total: u63 = 0;
185 while (total < count_actual) {206 while (total < count_actual) {
...@@ -204,10 +225,7 @@ pub const Stream = struct {...@@ -204,10 +225,7 @@ pub const Stream = struct {
204 pub const readInt = R.readInt;225 pub const readInt = R.readInt;
205 pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc;226 pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc;
206227
207 pub const ReadError = switch (builtin.target.os.tag) {228 pub const ReadError = sys.errno.Error;
208 .linux => sys.errno.Error,
209 else => @compileError("TODO"),
210 };
211 pub fn read(s: Stream, buffer: []u8) ReadError!usize {229 pub fn read(s: Stream, buffer: []u8) ReadError!usize {
212 return sys.recv(@intFromEnum(s.socket), buffer, 0);230 return sys.recv(@intFromEnum(s.socket), buffer, 0);
213 }231 }
...@@ -234,10 +252,7 @@ pub const Stream = struct {...@@ -234,10 +252,7 @@ pub const Stream = struct {
234 pub const writeIntPretty = W.writeIntPretty;252 pub const writeIntPretty = W.writeIntPretty;
235 pub const print = W.print;253 pub const print = W.print;
236254
237 pub const WriteError = switch (builtin.target.os.tag) {255 pub const WriteError = sys.errno.Error;
238 .linux => sys.errno.Error,
239 else => @compileError("TODO"),
240 };
241 pub fn write(s: Stream, bytes: []const u8) WriteError!usize {256 pub fn write(s: Stream, bytes: []const u8) WriteError!usize {
242 return sys.send(@intFromEnum(s.socket), bytes, 0);257 return sys.send(@intFromEnum(s.socket), bytes, 0);
243 }258 }
zigmod.yml+3
...@@ -9,5 +9,8 @@ dependencies:...@@ -9,5 +9,8 @@ dependencies:
9 - src: git https://github.com/nektro/zig-nfs9 - src: git https://github.com/nektro/zig-nfs
10 - src: git https://github.com/nektro/zig-time10 - src: git https://github.com/nektro/zig-time
11 - src: git https://github.com/nektro/zig-whatwg-url11 - 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
12root_dependencies:15root_dependencies:
13 - src: git https://github.com/nektro/zig-expect16 - src: git https://github.com/nektro/zig-expect