| ... | @@ -5,13 +5,24 @@ pub error SigInterrupt; | ... | @@ -5,13 +5,24 @@ pub error SigInterrupt; |
| 5 | pub error Unexpected; | 5 | pub error Unexpected; |
| 6 | | 6 | |
| 7 | pub fn os_get_random_bytes(buf: []u8) -> %void { | 7 | pub fn os_get_random_bytes(buf: []u8) -> %void { |
| 8 | const amt_got = getrandom(buf.ptr, buf.len, 0); | 8 | switch (@compile_var("os")) { |
| 9 | if (amt_got < 0) { | 9 | linux => { |
| 10 | return switch (-amt_got) { | 10 | const amt_got = getrandom(buf.ptr, buf.len, 0); |
| 11 | EINVAL => unreachable{}, | 11 | if (amt_got < 0) { |
| 12 | EFAULT => unreachable{}, | 12 | return switch (-amt_got) { |
| 13 | EINTR => error.SigInterrupt, | 13 | EINVAL => unreachable{}, |
| 14 | else => error.Unexpected, | 14 | EFAULT => unreachable{}, |
| 15 | } | 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 | } |