1 //! libc syscalls supporting `rustix::rand`. 2 3 #[cfg(target_os = "linux")] 4 use {super::super::c, super::super::conv::ret_ssize_t, crate::io, crate::rand::GetRandomFlags}; 5 6 #[cfg(target_os = "linux")] getrandom(buf: &mut [u8], flags: GetRandomFlags) -> io::Result<usize>7pub(crate) fn getrandom(buf: &mut [u8], flags: GetRandomFlags) -> io::Result<usize> { 8 // `getrandom` wasn't supported in glibc until 2.25. 9 weak_or_syscall! { 10 fn getrandom(buf: *mut c::c_void, buflen: c::size_t, flags: c::c_uint) via SYS_getrandom -> c::ssize_t 11 } 12 13 let nread = 14 unsafe { ret_ssize_t(getrandom(buf.as_mut_ptr().cast(), buf.len(), flags.bits()))? }; 15 Ok(nread as usize) 16 } 17