Browse Source

Add getrandom impl using ctru_sys bindings

pull/10/head
Ian Chamberlain 3 years ago committed by Andrea Ciliberti
parent
commit
fe0e7d7639
  1. 1
      Cargo.toml
  2. 16
      src/lib.rs

1
Cargo.toml

@ -6,4 +6,5 @@ license = "MIT/Apache 2.0" @@ -6,4 +6,5 @@ license = "MIT/Apache 2.0"
edition = "2018"
[dependencies]
ctru-sys = { git = "https://github.com/Meziu/ctru-rs.git" }
libc = "0.2.116"

16
src/lib.rs

@ -67,3 +67,19 @@ unsafe extern "C" fn clock_gettime( @@ -67,3 +67,19 @@ unsafe extern "C" fn clock_gettime(
retval
}
#[no_mangle]
unsafe extern "C" fn getrandom(
buf: *mut libc::c_void,
buflen: libc::size_t,
_flags: libc::c_uint,
) -> libc::ssize_t {
let ret = ctru_sys::psInit();
if ret != 0 {
return ret.try_into().unwrap();
}
ctru_sys::PS_GenerateRandomBytes(buf, buflen.try_into().unwrap())
.try_into()
.unwrap()
}

Loading…
Cancel
Save