Skip to content

Commit 86c2cd6

Browse files
authored
Use wasi isntead of libc (#64)
1 parent 10e41b2 commit 86c2cd6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ core = { version = "1.0", optional = true, package = "rustc-std-workspace-core"
2828
[target.'cfg(any(unix, target_os = "redox", target_os = "wasi"))'.dependencies]
2929
libc = { version = "0.2.60", default-features = false }
3030

31+
[target.'cfg(target_os = "wasi")'.dependencies]
32+
wasi = "0.5"
33+
3134
[target.wasm32-unknown-unknown.dependencies]
3235
wasm-bindgen = { version = "0.2.29", optional = true }
3336
stdweb = { version = "0.4.18", optional = true }

src/wasi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
//! Implementation for WASI
1010
use crate::Error;
1111
use core::num::NonZeroU32;
12+
use wasi::wasi_unstable::random_get;
1213

1314
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
14-
let ret =
15-
unsafe { libc::__wasi_random_get(dest.as_mut_ptr() as *mut libc::c_void, dest.len()) };
15+
let ret = random_get(dest);
1616
if let Some(code) = NonZeroU32::new(ret as u32) {
17-
error!("WASI: __wasi_random_get: failed with {}", ret);
17+
error!("WASI: random_get failed with return value {}", code);
1818
Err(Error::from(code))
1919
} else {
2020
Ok(()) // Zero means success for WASI

0 commit comments

Comments
 (0)