diff --git a/src/custom.rs b/src/custom.rs index 923b1cf8..fc216e08 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -1,14 +1,10 @@ //! An implementation which calls out to an externally defined function. use crate::Error; -use core::{mem::MaybeUninit, num::NonZeroU32}; +use core::mem::MaybeUninit; pub fn getrandom_inner(dest: &mut [MaybeUninit]) -> Result<(), Error> { extern "Rust" { - fn __getrandom_custom(dest: *mut u8, len: usize) -> u32; - } - let ret = unsafe { __getrandom_custom(dest.as_mut_ptr().cast(), dest.len()) }; - match NonZeroU32::new(ret) { - None => Ok(()), - Some(code) => Err(Error::from(code)), + fn __getrandom_custom(dest: *mut u8, len: usize) -> Result<(), Error>; } + unsafe { __getrandom_custom(dest.as_mut_ptr().cast(), dest.len()) } } diff --git a/src/lib.rs b/src/lib.rs index 62c2dab3..aeba316a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,7 +106,7 @@ //! //! ``` //! #[no_mangle] -//! unsafe fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 { +//! unsafe fn __getrandom_custom(dest: *mut u8, len: usize) -> Result<(), getrandom::Error> { //! todo!() //! } //! ``` @@ -127,8 +127,8 @@ //! use the following custom backend which always returns "unsupported" error: //! ``` //! #[no_mangle] -//! unsafe fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 { -//! getrandom::Error::UNSUPPORTED.code().get() +//! unsafe fn __getrandom_custom(dest: *mut u8, len: usize) -> Result<(), getrandom::Error> { +//! Err(getrandom::Error::UNSUPPORTED) //! } //! ``` //!