From 359a7964f9d1957e8463944fed2c58a46964d403 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 4 Jan 2023 10:27:29 -0700 Subject: [PATCH] implement `wasi-filesystem::readdir` and related functions (#45) * implement `wasi-filesystem::readdir` and related functions This adds a `directory_list` test and provides the required host implementation. I've also added a file length check to the `file_read` test, just to cover a bit more of the API. Signed-off-by: Joel Dice * fix memory corruption in `fd_readdir` polyfill We were copying `name.len() * 256` bytes instead of just `name.len()` bytes, which was overwriting other parts of `State` and causing untold havoc. Signed-off-by: Joel Dice * check type of entry in `Table::delete` Signed-off-by: Joel Dice Signed-off-by: Joel Dice --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5ad723e77266..d6c0a085f150 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -911,8 +911,8 @@ pub unsafe extern "C" fn fd_readdir( state.dirent_cache.cookie.set(cookie - 1); state.dirent_cache.cached_dirent.set(dirent); std::ptr::copy( - name.as_ptr().cast(), - (*state.dirent_cache.path_data.get()).as_mut_ptr(), + name.as_ptr().cast::(), + (*state.dirent_cache.path_data.get()).as_mut_ptr() as *mut u8, name.len(), ); break;