authorgravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-01-21 12:02:08+01:00
committergravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-01-21 12:02:08+01:00
log1ab6bf59a6722f816edce15574c2dfcaefeebd31
tree8feeb80293120b8c9ae6310896f5c052f929444d
parent4f652fb4e36c7f2791bb4c7fb1909a897a662c3b
signaturebadge-check Signed by SSH key SHA256:p3IHbr0lyK2ekfDC1Zi7dOEV/9T6lGghNawhl5sBnM4

feat(libzigc): add common linux errno syscall helper


2 files changed, 15 insertions(+), 9 deletions(-)

lib/c/common.zig+14
...@@ -13,3 +13,17 @@ pub const visibility: std.builtin.SymbolVisibility = if (linkage != .internal)...@@ -13,3 +13,17 @@ pub const visibility: std.builtin.SymbolVisibility = if (linkage != .internal)
13 .hidden13 .hidden
14else14else
15 .default;15 .default;
16
17/// Checks whether the syscall has had an error, storing it in `std.c.errno` and returning -1.
18/// Otherwise returns the result.
19pub fn linuxErrno(r: usize) isize {
20 const linux = std.os.linux;
21
22 return switch (linux.errno(r)) {
23 .SUCCESS => @bitCast(r),
24 else => |err| blk: {
25 std.c._errno().* = @intFromEnum(err);
26 break :blk -1;
27 },
28 };
29}
lib/c/sys/utsname.zig+1-9
...@@ -13,15 +13,7 @@ comptime {...@@ -13,15 +13,7 @@ comptime {
13}13}
1414
15fn unameLinux(uts: *std.os.linux.utsname) callconv(.c) c_int {15fn unameLinux(uts: *std.os.linux.utsname) callconv(.c) c_int {
16 const linux = std.os.linux;16 return @intCast(common.linuxErrno(std.os.linux.uname(uts)));
17
18 return switch (linux.errno(linux.uname(uts))) {
19 .SUCCESS => 0,
20 else => |err| blk: {
21 std.c._errno().* = @intFromEnum(err);
22 break :blk -1;
23 },
24 };
25}17}
2618
27fn unameWasi(uts: *std.c.utsname) callconv(.c) c_int {19fn unameWasi(uts: *std.c.utsname) callconv(.c) c_int {