wasi-common 0.1.0

WASI implementation in Rust
Documentation
diff --git a/src/host.rs b/src/host.rs
index 4b5b98f..8ae1112 100644
--- a/src/host.rs
+++ b/src/host.rs
@@ -560,10 +560,10 @@ pub unsafe fn ciovec_to_nix<'a>(ciovec: &'a __wasi_ciovec_t) -> nix::sys::uio::I
     nix::sys::uio::IoVec::from_slice(slice)
 }
 
-pub unsafe fn ciovec_to_nix_mut<'a>(
-    ciovec: &'a mut __wasi_ciovec_t,
+pub unsafe fn iovec_to_nix<'a>(
+    iovec: &'a mut __wasi_iovec_t,
 ) -> nix::sys::uio::IoVec<&'a mut [u8]> {
-    let slice = std::slice::from_raw_parts_mut(ciovec.buf as *mut u8, ciovec.buf_len);
+    let slice = std::slice::from_raw_parts_mut(iovec.buf as *mut u8, iovec.buf_len);
     nix::sys::uio::IoVec::from_mut_slice(slice)
 }
 
diff --git a/src/hostcalls.rs b/src/hostcalls.rs
index 3ae4c47..a618f84 100644
--- a/src/hostcalls.rs
+++ b/src/hostcalls.rs
@@ -411,7 +411,7 @@ pub fn fd_read(
     use nix::sys::uio::{readv, IoVec};
 
     let fd = dec_fd(fd);
-    let mut iovs = match dec_ciovec_slice(memory, iovs_ptr, iovs_len) {
+    let mut iovs = match dec_iovec_slice(memory, iovs_ptr, iovs_len) {
         Ok(iovs) => iovs,
         Err(e) => return enc_errno(e),
     };
@@ -423,7 +423,7 @@ pub fn fd_read(
 
     let mut iovs: Vec<IoVec<&mut [u8]>> = iovs
         .iter_mut()
-        .map(|iov| unsafe { host::ciovec_to_nix_mut(iov) })
+        .map(|iov| unsafe { host::iovec_to_nix(iov) })
         .collect();
 
     let host_nread = match readv(fe.fd_object.rawfd, &mut iovs) {
diff --git a/src/memory.rs b/src/memory.rs
index 45e673a..871339b 100644
--- a/src/memory.rs
+++ b/src/memory.rs
@@ -179,6 +179,26 @@ macro_rules! dec_enc_scalar {
     };
 }
 
+pub fn dec_iovec(
+    memory: &mut [u8],
+    iovec: &wasm32::__wasi_iovec_t,
+) -> Result<host::__wasi_iovec_t, host::__wasi_errno_t> {
+    let len = dec_usize(iovec.buf_len);
+    Ok(host::__wasi_iovec_t {
+        buf: dec_ptr_mut(memory, iovec.buf, len)? as *mut host::void,
+        buf_len: len,
+    })
+}
+
+pub fn dec_iovec_slice(
+    memory: &mut [u8],
+    ptr: wasm32::uintptr_t,
+    len: wasm32::size_t,
+) -> Result<Vec<host::__wasi_iovec_t>, host::__wasi_errno_t> {
+    let slice = dec_slice_of::<wasm32::__wasi_iovec_t>(memory, ptr, len)?;
+    slice.iter().map(|iov| dec_iovec(memory, iov)).collect()
+}
+
 pub fn dec_ciovec(
     memory: &[u8],
     ciovec: &wasm32::__wasi_ciovec_t,