Skip to content

Commit

Permalink
crypto.rand: fix compilation on macos with `-cc tcc -no-retry-compila…
Browse files Browse the repository at this point in the history
…tion -gc none`
  • Loading branch information
spytheman committed Sep 15, 2024
1 parent 26c560b commit 755a4bc
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions vlib/crypto/rand/rand_darwin.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down

0 comments on commit 755a4bc

Please sign in to comment.