Use wasi isntead of libc (#64)

This commit is contained in:
Artyom Pavlov
2019-08-08 08:02:19 +00:00
committed by GitHub
parent 10e41b22d6
commit 86c2cd6265
2 changed files with 6 additions and 3 deletions
+3
View File
@@ -28,6 +28,9 @@ core = { version = "1.0", optional = true, package = "rustc-std-workspace-core"
[target.'cfg(any(unix, target_os = "redox", target_os = "wasi"))'.dependencies]
libc = { version = "0.2.60", default-features = false }
[target.'cfg(target_os = "wasi")'.dependencies]
wasi = "0.5"
[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = { version = "0.2.29", optional = true }
stdweb = { version = "0.4.18", optional = true }
+3 -3
View File
@@ -9,12 +9,12 @@
//! Implementation for WASI
use crate::Error;
use core::num::NonZeroU32;
use wasi::wasi_unstable::random_get;
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
let ret =
unsafe { libc::__wasi_random_get(dest.as_mut_ptr() as *mut libc::c_void, dest.len()) };
let ret = random_get(dest);
if let Some(code) = NonZeroU32::new(ret as u32) {
error!("WASI: __wasi_random_get: failed with {}", ret);
error!("WASI: random_get failed with return value {}", code);
Err(Error::from(code))
} else {
Ok(()) // Zero means success for WASI