| author | |
| committer | |
| log | 1ab6bf59a6722f816edce15574c2dfcaefeebd31 |
| tree | 8feeb80293120b8c9ae6310896f5c052f929444d |
| parent | 4f652fb4e36c7f2791bb4c7fb1909a897a662c3b |
| signature |
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 | .hidden | 13 | .hidden |
| 14 | else | 14 | else |
| 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. | ||
| 19 | pub 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 | } |
| 14 | 14 | ||
| 15 | fn unameLinux(uts: *std.os.linux.utsname) callconv(.c) c_int { | 15 | fn 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 | } |
| 26 | 18 | ||
| 27 | fn unameWasi(uts: *std.c.utsname) callconv(.c) c_int { | 19 | fn unameWasi(uts: *std.c.utsname) callconv(.c) c_int { |