| author | |
| committer | |
| log | e6ef00233e77758fb0ae33a9ad52ed9011005e45 |
| tree | cf7723651556ca6040c3c8e9ce088853d6be6a77 |
| parent | 8621e3b5bd814005129b58469d93c2499e3d085e |
| parent | f2bef0447a523e6f21ab21e4845aa982a1332572 |
| signature |
Fix #3015 - fix RtlGenRandom function signature2 files changed, 13 insertions(+), 4 deletions(-)
std/os/windows.zig+12-3| ... | ... | @@ -138,10 +138,19 @@ pub const RtlGenRandomError = error{Unexpected}; |
| 138 | 138 | /// https://github.com/rust-lang-nursery/rand/issues/111 |
| 139 | 139 | /// https://bugzilla.mozilla.org/show_bug.cgi?id=504270 |
| 140 | 140 | pub fn RtlGenRandom(output: []u8) RtlGenRandomError!void { |
| 141 | if (advapi32.RtlGenRandom(output.ptr, output.len) == 0) { | |
| 142 | switch (kernel32.GetLastError()) { | |
| 143 | else => |err| return unexpectedError(err), | |
| 141 | var total_read: usize = 0; | |
| 142 | var buff: []u8 = output[0..]; | |
| 143 | const max_read_size: ULONG = maxInt(ULONG); | |
| 144 | ||
| 145 | while (total_read < output.len) { | |
| 146 | const to_read: ULONG = math.min(buff.len, max_read_size); | |
| 147 | ||
| 148 | if (advapi32.RtlGenRandom(buff.ptr, to_read) == 0) { | |
| 149 | return unexpectedError(kernel32.GetLastError()); | |
| 144 | 150 | } |
| 151 | ||
| 152 | total_read += to_read; | |
| 153 | buff = buff[to_read..]; | |
| 145 | 154 | } |
| 146 | 155 | } |
| 147 | 156 |
std/os/windows/advapi32.zig+1-1| ... | ... | @@ -19,5 +19,5 @@ pub extern "advapi32" stdcallcc fn RegQueryValueExW( |
| 19 | 19 | |
| 20 | 20 | // RtlGenRandom is known as SystemFunction036 under advapi32 |
| 21 | 21 | // http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx */ |
| 22 | pub extern "advapi32" stdcallcc fn SystemFunction036(output: [*]u8, length: usize) BOOL; | |
| 22 | pub extern "advapi32" stdcallcc fn SystemFunction036(output: [*]u8, length: ULONG) BOOL; | |
| 23 | 23 | pub const RtlGenRandom = SystemFunction036; |