From e918b368d93f61e0af31facfa4bd46f452d827d3 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 24 Aug 2025 02:40:22 -0700 Subject: [PATCH] use sys-libc --- licenses.txt | 6 ++++++ src/lib.zig | 11 ++++++----- zig.mod | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/licenses.txt b/licenses.txt index d4c94a95e939601ac7a79c42e59b40136b7f73e1..93caa3bb683f69e316307c76fcc3c6eb47084ddc 100644 --- a/licenses.txt +++ b/licenses.txt @@ -1,4 +1,10 @@ MIT: = https://spdx.org/licenses/MIT - This +- git https://github.com/nektro/zig-errno - git https://github.com/nektro/zig-extras +- git https://github.com/nektro/zig-libc +- git https://github.com/nektro/zig-sys-libc + +Unspecified: +- system_lib c diff --git a/src/lib.zig b/src/lib.zig index 7c32ffe93cf64105119615873db5ebb6c38b11f7..a6355133ded102568be148b4030743e311b6aadc 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -2,6 +2,7 @@ const std = @import("std"); const string = []const u8; const List = std.ArrayList(string); const extras = @import("extras"); +const libc = @import("sys-libc"); var singles: std.StringArrayHashMap(string) = undefined; var multis: std.StringArrayHashMap(List) = undefined; @@ -67,7 +68,7 @@ pub fn parse(k: FlagDashKind) !std.process.ArgIterator { } } std.log.err("Unrecognized argument: {s}{s}", .{ dash, name }); - std.posix.exit(1); + libc.exit(1); } return argiter; } @@ -78,7 +79,7 @@ pub fn parseEnv() !void { for (singles.keys(), singles.values()) |k, *v| { const u = try fixNameForEnv(alloc, k); defer alloc.free(u); - if (std.posix.getenv(u)) |value| { + if (libc.getenv(u)) |value| { v.* = value; } } @@ -87,9 +88,9 @@ pub fn parseEnv() !void { while (true) : (n += 1) { const u = try fixNameForEnv(alloc, k); defer alloc.free(u); - const w = try std.fmt.allocPrint(alloc, "{s}_{d}", .{ u, n }); + const w = try std.fmt.allocPrintZ(alloc, "{s}_{d}", .{ u, n }); defer alloc.free(w); - if (std.posix.getenv(w)) |value| { + if (libc.getenv(w)) |value| { try v.append(value); continue; } @@ -98,7 +99,7 @@ pub fn parseEnv() !void { } } -fn fixNameForEnv(alloc: std.mem.Allocator, input: string) !string { +fn fixNameForEnv(alloc: std.mem.Allocator, input: string) ![:0]const u8 { var ret = try extras.asciiUpper(alloc, input); for (0..ret.len) |i| { if (ret[i] == '-') { diff --git a/zig.mod b/zig.mod index 4f6013c15483e8dabf3b309637cc83122bfa7501..adbb0b96ee0121c2e55fd07764d3c2d1b0ff1d39 100644 --- a/zig.mod +++ b/zig.mod @@ -5,3 +5,4 @@ license: MIT description: Config management for Zig. dependencies: - src: git https://github.com/nektro/zig-extras + - src: git https://github.com/nektro/zig-sys-libc -- 2.54.0