From 1e98900cd5f33455b5fef767640f6669f7b3dc35 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 23 Aug 2026 18:54:16 -0700 Subject: [PATCH] add support for freebsd, netbsd, openbsd --- licenses.txt | 3 +++ src/postgresql.zig | 8 +++++--- zig.mod | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/licenses.txt b/licenses.txt index 7197361534bc63a483c901c5ccb72ce3ab3d8708..2ed5f12c76e230b5ce91ebb287bf6d4a2bad33dd 100644 --- a/licenses.txt +++ b/licenses.txt @@ -11,7 +11,10 @@ MIT: = https://spdx.org/licenses/MIT - 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-tracer - git https://github.com/nektro/zig-unicode-ucd diff --git a/src/postgresql.zig b/src/postgresql.zig index 3dedd1dc0559acc5f5ad02c15d3d6de925d650a7..29909cac0de51b4a75fe03ef3cef1ac7b971953d 100644 --- a/src/postgresql.zig +++ b/src/postgresql.zig @@ -11,6 +11,9 @@ const tracer = @import("tracer"); const sys = switch (builtin.target.os.tag) { .linux => @import("sys-linux"), + .freebsd => @import("sys-freebsd"), + .netbsd => @import("sys-netbsd"), + .openbsd => @import("sys-openbsd"), else => unreachable, }; @@ -37,8 +40,7 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver { // https://github.com/postgres/postgres/blob/REL_18_0/src/include/common/scram-common.h#L32-L37 const nonce_len = 18; - var cnonce_buf: [nonce_len]u8 = @splat(0); - var cnonce = try sys.getrandom(&cnonce_buf, 0); + const cnonce = nio.randomBytes(nonce_len); _ = &cnonce; var snonce_b64_buf: [128]u8 = @splat(0); @@ -111,7 +113,7 @@ pub fn connect(allocator: std.mem.Allocator, connect_s: [:0]const u8) !Driver { // server-error-value = "invalid-encoding" / "extensions-not-supported" / "invalid-proof" / "channel-bindings-dont-match" / "server-does-support-channel-binding" / "channel-binding-not-supported" / "unsupported-channel-binding-type" / "unknown-user" / "invalid-username-encoding" / "no-resources" / "other-error" / server-error-value-ext var cnonce_b64_buf: [Base64Enc.calcSize(nonce_len)]u8 = @splat(0); - const cnonce_b64 = Base64Enc.encode(&cnonce_b64_buf, cnonce); + const cnonce_b64 = Base64Enc.encode(&cnonce_b64_buf, &cnonce); var salt_b64_buf: [128]u8 = @splat(0); var salt_b64: []u8 = salt_b64_buf[0..]; diff --git a/zig.mod b/zig.mod index f256703828bca260871267cbb1bdd749610b17c5..eed3f13afa013f007021c5793f54f6971763b66a 100644 --- a/zig.mod +++ b/zig.mod @@ -19,3 +19,6 @@ dependencies: - src: git https://github.com/nektro/zig-net - src: git https://github.com/nektro/zig-nio - src: git https://github.com/nektro/zig-sys-linux + - 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 -- 2.54.0