diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-07-26 20:49:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-26 20:49:11 +0200 |
| commit | 26d791b351e98537a6ac9962ff14b8e1b5b4f2e2 (patch) | |
| tree | 971f7cd7d395050122f9e2d7ca6d2848cbfbfcf1 /library/std/src/sys/unix/rand.rs | |
| parent | 601a34de8c10458b72a7781eb0b44a7981e4a2b1 (diff) | |
| parent | a7e0bab76bf28f7fe9791a2b412f8bccb061696f (diff) | |
| download | rust-26d791b351e98537a6ac9962ff14b8e1b5b4f2e2.tar.gz rust-26d791b351e98537a6ac9962ff14b8e1b5b4f2e2.zip | |
Rollup merge of #101994 - devnexen:rand_fbsd_update, r=workingjubilee
rand: freebsd update, using getrandom. supported since the 12th release, while 11.4 is EOL since 2021.
Diffstat (limited to 'library/std/src/sys/unix/rand.rs')
| -rw-r--r-- | library/std/src/sys/unix/rand.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/library/std/src/sys/unix/rand.rs b/library/std/src/sys/unix/rand.rs index d471be33ed5..fbf158f56fc 100644 --- a/library/std/src/sys/unix/rand.rs +++ b/library/std/src/sys/unix/rand.rs @@ -17,7 +17,6 @@ pub fn hashmap_random_keys() -> (u64, u64) { not(target_os = "tvos"), not(target_os = "watchos"), not(target_os = "openbsd"), - not(target_os = "freebsd"), not(target_os = "netbsd"), not(target_os = "fuchsia"), not(target_os = "redox"), @@ -68,11 +67,25 @@ mod imp { 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 + extern "C" { + fn getrandom( + buffer: *mut libc::c_void, + length: libc::size_t, + flags: libc::c_uint, + ) -> libc::ssize_t; + } + unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) } + } + #[cfg(not(any( target_os = "linux", target_os = "android", target_os = "espidf", - target_os = "horizon" + target_os = "horizon", + target_os = "freebsd" )))] fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool { false @@ -82,7 +95,8 @@ mod imp { target_os = "linux", target_os = "android", target_os = "espidf", - target_os = "horizon" + target_os = "horizon", + target_os = "freebsd" ))] fn getrandom_fill_bytes(v: &mut [u8]) -> bool { use crate::sync::atomic::{AtomicBool, Ordering}; @@ -222,7 +236,7 @@ mod imp { } } -#[cfg(any(target_os = "freebsd", target_os = "netbsd"))] +#[cfg(target_os = "netbsd")] mod imp { use crate::ptr; |
