f1d338194e
* Introduce the concept of packages. Closes #3 * Add support for error notes. * Introduce `@import` and `@c_import` builtin functions and remove the `import` and `c_import` top level declarations. * Introduce the `use` top level declaration. * Add `--check-unused` parameter to perform semantic analysis and codegen on all top level declarations, not just exported ones and ones referenced by exported ones. * Delete the root export node and add `--library` argument.
29 lines
784 B
Zig
29 lines
784 B
Zig
const syscall = @import("syscall.zig");
|
|
const errno = @import("errno.zig");
|
|
|
|
pub error SigInterrupt;
|
|
pub error Unexpected;
|
|
|
|
pub fn get_random_bytes(buf: []u8) -> %void {
|
|
switch (@compile_var("os")) {
|
|
linux => {
|
|
const amt_got = syscall.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,
|
|
}
|
|
}
|
|
},
|
|
windows => {
|
|
// TODO
|
|
for (buf) |_, i| {
|
|
buf[i] = 4;
|
|
}
|
|
},
|
|
else => unreachable{},
|
|
}
|
|
}
|