| ... | ... | @@ -5,13 +5,24 @@ pub error SigInterrupt; |
| 5 | 5 | pub error Unexpected; |
| 6 | 6 | |
| 7 | 7 | pub fn os_get_random_bytes(buf: []u8) -> %void { |
| 8 | | const amt_got = getrandom(buf.ptr, buf.len, 0); |
| 9 | | if (amt_got < 0) { |
| 10 | | return switch (-amt_got) { |
| 11 | | EINVAL => unreachable{}, |
| 12 | | EFAULT => unreachable{}, |
| 13 | | EINTR => error.SigInterrupt, |
| 14 | | else => error.Unexpected, |
| 15 | | } |
| 8 | switch (@compile_var("os")) { |
| 9 | linux => { |
| 10 | const amt_got = getrandom(buf.ptr, buf.len, 0); |
| 11 | if (amt_got < 0) { |
| 12 | return switch (-amt_got) { |
| 13 | EINVAL => unreachable{}, |
| 14 | EFAULT => unreachable{}, |
| 15 | EINTR => error.SigInterrupt, |
| 16 | else => error.Unexpected, |
| 17 | } |
| 18 | } |
| 19 | }, |
| 20 | windows => { |
| 21 | // TODO |
| 22 | for (buf) |_, i| { |
| 23 | buf[i] = 4; |
| 24 | } |
| 25 | }, |
| 26 | else => unreachable{}, |
| 16 | 27 | } |
| 17 | 28 | } |