Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions crates/test-programs/wasi-tests/src/bin/fd_filestat_get.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
unsafe fn test_fd_filestat_get() {

let stat = wasi::fd_filestat_get(libc::STDIN_FILENO as u32).expect("failed filestat 0");
assert_eq!(stat.size, 0, "stdio size should be 0");
assert_eq!(stat.atim, 0, "stdio atim should be 0");
assert_eq!(stat.mtim, 0, "stdio mtim should be 0");
assert_eq!(stat.ctim, 0, "stdio ctim should be 0");

let stat = wasi::fd_filestat_get(libc::STDOUT_FILENO as u32).expect("failed filestat 1");
assert_eq!(stat.size, 0, "stdio size should be 0");
assert_eq!(stat.atim, 0, "stdio atim should be 0");
assert_eq!(stat.mtim, 0, "stdio mtim should be 0");
assert_eq!(stat.ctim, 0, "stdio ctim should be 0");

let stat = wasi::fd_filestat_get(libc::STDERR_FILENO as u32).expect("failed filestat 2");
assert_eq!(stat.size, 0, "stdio size should be 0");
assert_eq!(stat.atim, 0, "stdio atim should be 0");
assert_eq!(stat.mtim, 0, "stdio mtim should be 0");
assert_eq!(stat.ctim, 0, "stdio ctim should be 0");
}

fn main() {
// Run the tests.
unsafe { test_fd_filestat_get() }
}
15 changes: 1 addition & 14 deletions crates/wasi-common/cap-std-sync/src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use io_lifetimes::{AsFd, BorrowedFd};
#[cfg(windows)]
use io_lifetimes::{AsHandle, BorrowedHandle};
use wasi_common::{
file::{FdFlags, FileType, Filestat, WasiFile},
file::{FdFlags, FileType, WasiFile},
Error, ErrorExt,
};

Expand Down Expand Up @@ -126,19 +126,6 @@ macro_rules! wasi_file_write_impl {
async fn get_fdflags(&mut self) -> Result<FdFlags, Error> {
Ok(FdFlags::APPEND)
}
async fn get_filestat(&mut self) -> Result<Filestat, Error> {
let meta = self.0.as_filelike_view::<File>().metadata()?;
Ok(Filestat {
device_id: 0,
inode: 0,
filetype: self.get_filetype().await?,
nlink: 0,
size: meta.len(),
atim: meta.accessed().ok(),
mtim: meta.modified().ok(),
ctim: meta.created().ok(),
})
}
async fn write_vectored<'a>(&mut self, bufs: &[io::IoSlice<'a>]) -> Result<u64, Error> {
let n = (&*self.0.as_filelike_view::<File>()).write_vectored(bufs)?;
Ok(n.try_into().map_err(|c| Error::range().context(c))?)
Expand Down