Debian Codegraph @

.cargo/vendor/getrandom/src/backends/getentropy.rs

raw
1 //! Implementation using getentropy(2)
2 //!
3 //! Available since:
4 //! - macOS 10.12
5 //! - OpenBSD 5.6
6 //! - Emscripten 2.0.5
7 //! - vita newlib since Dec 2021
8 //!
9 //! For these targets, we use getentropy(2) because getrandom(2) doesn't exist.
10 use crate::Error;
11 use core::{ffi::c_void, mem::MaybeUninit};
12
13 pub use crate::util::{inner_u32, inner_u64};
14
15 #[path = "../util_libc.rs"]
16 mod util_libc;
17
18 #[inline]
19 pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
20 for chunk in dest.chunks_mut(256) {
21 let ret = unsafe { libc::getentropy(chunk.as_mut_ptr().cast::<c_void>(), chunk.len()) };
22 if ret != 0 {
23 return Err(util_libc::last_os_error());
24 }
25 }
26 Ok(())
27 }