authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-08-24 02:40:22 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-08-24 02:40:22 -07:00
loge918b368d93f61e0af31facfa4bd46f452d827d3
tree1b2e3a3bc0ba3ac5d6729123f8160d7d8150861d
parente5c0a7088040fd61b764a4339e93a6ce67574700

use sys-libc


3 files changed, 13 insertions(+), 5 deletions(-)

licenses.txt+6
...@@ -1,4 +1,10 @@...@@ -1,4 +1,10 @@
1MIT:1MIT:
2= https://spdx.org/licenses/MIT2= https://spdx.org/licenses/MIT
3- This3- This
4- git https://github.com/nektro/zig-errno
4- git https://github.com/nektro/zig-extras5- git https://github.com/nektro/zig-extras
6- git https://github.com/nektro/zig-libc
7- git https://github.com/nektro/zig-sys-libc
8
9Unspecified:
10- system_lib c
src/lib.zig+6-5
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const List = std.ArrayList(string);3const List = std.ArrayList(string);
4const extras = @import("extras");4const extras = @import("extras");
5const libc = @import("sys-libc");
56
6var singles: std.StringArrayHashMap(string) = undefined;7var singles: std.StringArrayHashMap(string) = undefined;
7var multis: std.StringArrayHashMap(List) = undefined;8var multis: std.StringArrayHashMap(List) = undefined;
...@@ -67,7 +68,7 @@ pub fn parse(k: FlagDashKind) !std.process.ArgIterator {...@@ -67,7 +68,7 @@ pub fn parse(k: FlagDashKind) !std.process.ArgIterator {
67 }68 }
68 }69 }
69 std.log.err("Unrecognized argument: {s}{s}", .{ dash, name });70 std.log.err("Unrecognized argument: {s}{s}", .{ dash, name });
70 std.posix.exit(1);71 libc.exit(1);
71 }72 }
72 return argiter;73 return argiter;
73}74}
...@@ -78,7 +79,7 @@ pub fn parseEnv() !void {...@@ -78,7 +79,7 @@ pub fn parseEnv() !void {
78 for (singles.keys(), singles.values()) |k, *v| {79 for (singles.keys(), singles.values()) |k, *v| {
79 const u = try fixNameForEnv(alloc, k);80 const u = try fixNameForEnv(alloc, k);
80 defer alloc.free(u);81 defer alloc.free(u);
81 if (std.posix.getenv(u)) |value| {82 if (libc.getenv(u)) |value| {
82 v.* = value;83 v.* = value;
83 }84 }
84 }85 }
...@@ -87,9 +88,9 @@ pub fn parseEnv() !void {...@@ -87,9 +88,9 @@ pub fn parseEnv() !void {
87 while (true) : (n += 1) {88 while (true) : (n += 1) {
88 const u = try fixNameForEnv(alloc, k);89 const u = try fixNameForEnv(alloc, k);
89 defer alloc.free(u);90 defer alloc.free(u);
90 const w = try std.fmt.allocPrint(alloc, "{s}_{d}", .{ u, n });91 const w = try std.fmt.allocPrintZ(alloc, "{s}_{d}", .{ u, n });
91 defer alloc.free(w);92 defer alloc.free(w);
92 if (std.posix.getenv(w)) |value| {93 if (libc.getenv(w)) |value| {
93 try v.append(value);94 try v.append(value);
94 continue;95 continue;
95 }96 }
...@@ -98,7 +99,7 @@ pub fn parseEnv() !void {...@@ -98,7 +99,7 @@ pub fn parseEnv() !void {
98 }99 }
99}100}
100101
101fn fixNameForEnv(alloc: std.mem.Allocator, input: string) !string {102fn fixNameForEnv(alloc: std.mem.Allocator, input: string) ![:0]const u8 {
102 var ret = try extras.asciiUpper(alloc, input);103 var ret = try extras.asciiUpper(alloc, input);
103 for (0..ret.len) |i| {104 for (0..ret.len) |i| {
104 if (ret[i] == '-') {105 if (ret[i] == '-') {
zig.mod+1
...@@ -5,3 +5,4 @@ license: MIT...@@ -5,3 +5,4 @@ license: MIT
5description: Config management for Zig.5description: Config management for Zig.
6dependencies:6dependencies:
7 - src: git https://github.com/nektro/zig-extras7 - src: git https://github.com/nektro/zig-extras
8 - src: git https://github.com/nektro/zig-sys-libc