8b8b00da01
Returning a negative number of bytes makes absolutely no sense, besides the "-1 and errno" pattern, which is now converted to Result<_, Errno>.
20 lines
446 B
Rust
20 lines
446 B
Rust
use core::slice;
|
|
|
|
use crate::{
|
|
error::ResultExt,
|
|
platform::{types::*, Pal, Sys},
|
|
};
|
|
|
|
pub const GRND_NONBLOCK: c_uint = 1;
|
|
pub const GRND_RANDOM: c_uint = 2;
|
|
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn getrandom(buf: *mut c_void, buflen: size_t, flags: c_uint) -> ssize_t {
|
|
Sys::getrandom(
|
|
slice::from_raw_parts_mut(buf as *mut u8, buflen as usize),
|
|
flags,
|
|
)
|
|
.map(|read| read as ssize_t)
|
|
.or_minus_one_errno()
|
|
}
|