| ... | @@ -512,7 +512,18 @@ pub fn getrandom(buffer: []u8) GetRandomError!void { | ... | @@ -512,7 +512,18 @@ pub fn getrandom(buffer: []u8) GetRandomError!void { |
| 512 | return; | 512 | return; |
| 513 | } | 513 | } |
| 514 | switch (builtin.os.tag) { | 514 | switch (builtin.os.tag) { |
| 515 | .netbsd, .openbsd, .macos, .ios, .tvos, .watchos => { | 515 | .macos, .ios => { |
| | 516 | const rc = darwin.CCRandomGenerateBytes(buffer.ptr, buffer.len); |
| | 517 | if (rc != darwin.CCRNGStatus.kCCSuccess) { |
| | 518 | if (rc == darwin.CCRNGStatus.kCCParamError or rc == darwin.CCRNGStatus.kCCBufferTooSmall) { |
| | 519 | return error.InvalidHandle; |
| | 520 | } else { |
| | 521 | return error.SystemResources; |
| | 522 | } |
| | 523 | } |
| | 524 | return; |
| | 525 | }, |
| | 526 | .netbsd, .openbsd, .tvos, .watchos => { |
| 516 | system.arc4random_buf(buffer.ptr, buffer.len); | 527 | system.arc4random_buf(buffer.ptr, buffer.len); |
| 517 | return; | 528 | return; |
| 518 | }, | 529 | }, |
| ... | @@ -991,7 +1002,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { | ... | @@ -991,7 +1002,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { |
| 991 | if (have_pread_but_not_preadv) { | 1002 | if (have_pread_but_not_preadv) { |
| 992 | // We could loop here; but proper usage of `preadv` must handle partial reads anyway. | 1003 | // We could loop here; but proper usage of `preadv` must handle partial reads anyway. |
| 993 | // So we simply read into the first vector only. | 1004 | // So we simply read into the first vector only. |
| 994 | if (iov.len == 0) return @as(usize, 0); | 1005 | if (iov.len == 0) return @intCast(usize, 0); |
| 995 | const first = iov[0]; | 1006 | const first = iov[0]; |
| 996 | return pread(fd, first.iov_base[0..first.iov_len], offset); | 1007 | return pread(fd, first.iov_base[0..first.iov_len], offset); |
| 997 | } | 1008 | } |