Skip to content

Commit

Permalink
rand use getrandom for freebsd (available since 12.x)
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Jul 30, 2023
1 parent 2e0136a commit 4b73cf3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions library/std/src/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,15 @@ mod imp {
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) }
}

#[cfg(any(target_os = "espidf", target_os = "horizon"))]
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd"))]
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
}

#[cfg(target_os = "freebsd")]
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
// FIXME: using the above when libary std's libc is updated
#[cfg(not(target_os = "freebsd"))]
use libc::getrandom;
#[cfg(target_os = "freebsd")]
extern "C" {
fn getrandom(
buffer: *mut libc::c_void,
length: libc::size_t,
buf: *mut libc::c_void,
buflen: libc::size_t,
flags: libc::c_uint,
) -> libc::ssize_t;
}
Expand Down Expand Up @@ -236,6 +233,7 @@ mod imp {
}
}

// FIXME: once the 10.x release becomes the minimum, this can be dropped for simplification.
#[cfg(target_os = "netbsd")]
mod imp {
use crate::ptr;
Expand Down

0 comments on commit 4b73cf3

Please sign in to comment.