Skip to content

Commit

Permalink
Use wasi isntead of libc (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Aug 8, 2019
1 parent 10e41b2 commit 86c2cd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 3 additions & 3 deletions src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 86c2cd6

Please sign in to comment.