mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
crypto.rand: fix compilation on macos with -cc tcc -no-retry-compilation -gc none
This commit is contained in:
parent
26c560bc82
commit
755a4bc081
1 changed files with 3 additions and 5 deletions
|
@ -4,16 +4,14 @@
|
|||
|
||||
module rand
|
||||
|
||||
#include <Security/SecRandom.h>
|
||||
#include <sys/random.h>
|
||||
|
||||
#flag darwin -framework Security
|
||||
|
||||
fn C.SecRandomCopyBytes(rnd C.SecRandomRef, count usize, bytes voidptr) int
|
||||
fn C.getentropy(buf voidptr, buflen usize) int
|
||||
|
||||
// read returns an array of `bytes_needed` random bytes read from the OS.
|
||||
pub fn read(bytes_needed int) ![]u8 {
|
||||
mut buffer := []u8{len: bytes_needed}
|
||||
status := C.SecRandomCopyBytes(C.SecRandomRef(0), bytes_needed, buffer.data)
|
||||
status := C.getentropy(buffer.data, bytes_needed)
|
||||
if status != 0 {
|
||||
return &ReadError{}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue