Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Implement fd_filestat_set_size using libstd #47

Merged
merged 2 commits into from
Aug 8, 2019
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
5 changes: 3 additions & 2 deletions src/hostcalls_impl/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ pub(crate) fn fd_allocate(

let current_size = metadata.len();
let wanted_size = offset.checked_add(len).ok_or(host::__WASI_E2BIG)?;
// This check will be unnecessary when rust-lang/rust#63326 is fixed
if wanted_size > i64::max_value() as u64 {
return Err(host::__WASI_E2BIG);
}
Expand Down Expand Up @@ -779,11 +780,11 @@ pub(crate) fn fd_filestat_set_size(
.and_then(|fe| fe.fd_object.descriptor.as_file())?;

let st_size = dec_filesize(st_size);
// This check will be unnecessary when rust-lang/rust#63326 is fixed
if st_size > i64::max_value() as u64 {
return Err(host::__WASI_E2BIG);
}

hostcalls_impl::fd_filestat_set_size(fd, st_size)
fd.set_len(st_size).map_err(errno_from_ioerror)
}

pub(crate) fn path_filestat_get(
Expand Down
6 changes: 0 additions & 6 deletions src/sys/unix/hostcalls_impl/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,6 @@ pub(crate) fn fd_filestat_set_times(
}
}

pub(crate) fn fd_filestat_set_size(fd: &File, st_size: host::__wasi_filesize_t) -> Result<()> {
use nix::unistd::ftruncate;
ftruncate(fd.as_raw_fd(), st_size as off_t)
.map_err(|e| host_impl::errno_from_nix(e.as_errno().unwrap()))
}

pub(crate) fn path_filestat_get(
resolved: PathGet,
dirflags: host::__wasi_lookupflags_t,
Expand Down
4 changes: 0 additions & 4 deletions src/sys/windows/hostcalls_impl/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,6 @@ pub(crate) fn fd_filestat_set_times(
unimplemented!("fd_filestat_set_times")
}

pub(crate) fn fd_filestat_set_size(fd: &File, st_size: host::__wasi_filesize_t) -> Result<()> {
unimplemented!("fd_filestat_set_size")
}

pub(crate) fn path_filestat_get(
resolved: PathGet,
dirflags: host::__wasi_lookupflags_t,
Expand Down