diff options
| author | flysand7 <yyakut.ac@gmail.com> | 2023-10-18 01:57:26 +1100 |
|---|---|---|
| committer | flysand7 <yyakut.ac@gmail.com> | 2023-10-27 10:51:21 +1100 |
| commit | 4d65b1ab9cb86bcbbfb0e5b26e3552f6f3582004 (patch) | |
| tree | b61fb2dbcfe8fbd8574cbda546c27ed91e49d44a /core/math | |
| parent | 8e4bdcfb9837d70e94634db02e79a06036a3dde7 (diff) | |
Implement new sys/unix package
Diffstat (limited to 'core/math')
| -rw-r--r-- | core/math/rand/system_linux.odin | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/core/math/rand/system_linux.odin b/core/math/rand/system_linux.odin index 2923b77be..42c9f86fa 100644 --- a/core/math/rand/system_linux.odin +++ b/core/math/rand/system_linux.odin @@ -1,27 +1,28 @@ package rand -import "core:sys/unix" +import "core:sys/linux" @(require_results) _system_random :: proc() -> u64 { for { value: u64 - ret := unix.sys_getrandom(([^]u8)(&value), size_of(value), 0) - if ret < 0 { - switch ret { - case -4: // EINTR - // Call interupted by a signal handler, just retry the request. - continue - case -38: // ENOSYS - // The kernel is apparently prehistoric (< 3.17 circa 2014) - // and does not support getrandom. - panic("getrandom not available in kernel") - case: - // All other failures are things that should NEVER happen - // unless the kernel interface changes (ie: the Linux - // developers break userland). - panic("getrandom failed") - } + value_buf := (cast([^]u8)&value)[:size_of(u64)] + _, errno := linux.getrandom(value_buf, {}) + #partial switch errno { + case .NONE: + // Do nothing + case .EINTR: + // Call interupted by a signal handler, just retry the request. + continue + case .ENOSYS: + // The kernel is apparently prehistoric (< 3.17 circa 2014) + // and does not support getrandom. + panic("getrandom not available in kernel") + case: + // All other failures are things that should NEVER happen + // unless the kernel interface changes (ie: the Linux + // developers break userland). + panic("getrandom failed") } return value } |