Error doc; fix for Solaris

This commit is contained in:
Diggory Hardy 2019-02-18 12:50:37 +00:00
parent 9ba1d37952
commit 7ff3aff076
2 changed files with 13 additions and 2 deletions

View File

@ -12,18 +12,29 @@ use core::fmt;
#[cfg(not(target_env = "sgx"))]
use std::{io, error};
/// An unknown error.
pub const UNKNOWN_ERROR: Error = Error(unsafe {
NonZeroU32::new_unchecked(0x756e6b6e) // "unkn"
});
/// No generator is available.
pub const UNAVAILABLE_ERROR: Error = Error(unsafe {
NonZeroU32::new_unchecked(0x4e416e61) // "NAna"
});
/// The error type.
///
/// This type is small and no-std compatible.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Error(NonZeroU32);
impl Error {
/// Extract the error code.
///
/// This may equal one of the codes defined in this library or may be a
/// system error code.
///
/// One may attempt to format this error via the `Display` implementation.
pub fn code(&self) -> NonZeroU32 {
self.0
}

View File

@ -48,7 +48,7 @@ fn syscall_getrandom(dest: &mut [u8]) -> Result<(), Error> {
syscall(SYS_GETRANDOM, dest.as_mut_ptr(), dest.len(), 0)
};
if ret == -1 || ret != dest.len() as i64 {
return Err(io::Error::last_os_error().from());
return Err(io::Error::last_os_error().into());
}
Ok(())
}
@ -75,7 +75,7 @@ pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
},
}
})
}).map_err(|_| Error::Unknown)
})
}
fn is_getrandom_available() -> bool {