mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 04:24:33 +01:00
feat(libzigc): add common linux errno syscall helper
This commit is contained in:
parent
4f652fb4e3
commit
1ab6bf59a6
2 changed files with 15 additions and 9 deletions
|
|
@ -13,3 +13,17 @@ pub const visibility: std.builtin.SymbolVisibility = if (linkage != .internal)
|
|||
.hidden
|
||||
else
|
||||
.default;
|
||||
|
||||
/// Checks whether the syscall has had an error, storing it in `std.c.errno` and returning -1.
|
||||
/// Otherwise returns the result.
|
||||
pub fn linuxErrno(r: usize) isize {
|
||||
const linux = std.os.linux;
|
||||
|
||||
return switch (linux.errno(r)) {
|
||||
.SUCCESS => @bitCast(r),
|
||||
else => |err| blk: {
|
||||
std.c._errno().* = @intFromEnum(err);
|
||||
break :blk -1;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,15 +13,7 @@ comptime {
|
|||
}
|
||||
|
||||
fn unameLinux(uts: *std.os.linux.utsname) callconv(.c) c_int {
|
||||
const linux = std.os.linux;
|
||||
|
||||
return switch (linux.errno(linux.uname(uts))) {
|
||||
.SUCCESS => 0,
|
||||
else => |err| blk: {
|
||||
std.c._errno().* = @intFromEnum(err);
|
||||
break :blk -1;
|
||||
},
|
||||
};
|
||||
return @intCast(common.linuxErrno(std.os.linux.uname(uts)));
|
||||
}
|
||||
|
||||
fn unameWasi(uts: *std.c.utsname) callconv(.c) c_int {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue