Given a low-level syscall return value, sets errno and returns -1, or on
success returns the result.
pub fn errno(syscall_return_value: usize) c_int
pub fn errno(syscall_return_value: usize) c_int {
return switch (builtin.os.tag) {
.linux => {
const signed: isize = @bitCast(syscall_return_value);
const casted: c_int = @intCast(signed);
if (casted < 0) {
@branchHint(.unlikely);
std.c._errno().* = -casted;
return -1;
}
return casted;
},
else => comptime unreachable,
};
}