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, Error}; 11 getrandom_inner(dest: &mut [u8]) -> Result<(), Error>12pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { 13 for chunk in dest.chunks_mut(256) { 14 let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) }; 15 if ret == -1 { 16 return Err(last_os_error()); 17 } 18 } 19 Ok(()) 20 } 21