diff --git a/Cargo.toml b/Cargo.toml index dc453fc..76e70da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index 7783976..0e7db60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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() +}