zig/std/os.zig

31 lines
792 B
Zig
Raw Normal View History

2016-03-02 05:11:38 +08:00
const linux = @import("linux.zig");
const errno = @import("errno.zig");
2016-02-04 16:00:54 +08:00
pub error SigInterrupt;
pub error Unexpected;
pub fn get_random_bytes(buf: []u8) -> %void {
switch (@compile_var("os")) {
linux => {
2016-03-02 05:11:38 +08:00
const amt_got = linux.getrandom(buf.ptr, buf.len, 0);
if (amt_got < 0) {
return switch (-amt_got) {
errno.EINVAL => unreachable{},
errno.EFAULT => unreachable{},
errno.EINTR => error.SigInterrupt,
else => error.Unexpected,
}
}
},
else => unreachable{},
2016-02-04 16:00:54 +08:00
}
}
2016-04-19 07:42:56 +08:00
#attribute("cold")
pub fn abort() -> unreachable {
linux.raise(linux.SIGABRT);
linux.raise(linux.SIGKILL);
while (true) {}
}