Files
RedBear-OS/src/header/sys_random/mod.rs
T
4lDO2 8b8b00da01 Use unsigned return values in read()-like Pal fns.
Returning a negative number of bytes makes absolutely no sense, besides
the "-1 and errno" pattern, which is now converted to Result<_, Errno>.
2024-09-27 10:39:26 +02:00

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()
}