crypto.rand: fix compilation on macos with -cc tcc -no-retry-compilation -gc none

This commit is contained in:
Delyan Angelov 2024-09-15 14:53:52 +03:00
parent 26c560bc82
commit 755a4bc081

View file

@ -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{}
}