1 // Copyright 2018 Developers of the Rand project. 2 // 3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or 4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license 5 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your 6 // option. This file may not be copied, modified, or distributed 7 // except according to those terms. 8 9 //! Implementation for OpenBSD 10 use crate::util_libc::last_os_error; 11 use crate::Error; 12 getrandom_inner(dest: &mut [u8]) -> Result<(), Error>13pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { 14 for chunk in dest.chunks_mut(256) { 15 let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) }; 16 if ret == -1 { 17 let err = last_os_error(); 18 error!("libc::getentropy call failed"); 19 return Err(err); 20 } 21 } 22 Ok(()) 23 } 24