Make fd_tell host independent
This commit is contained in:
@@ -340,15 +340,19 @@ pub fn fd_tell(
|
|||||||
trace!("fd_tell(fd={:?}, newoffset={:#x?})", fd, newoffset);
|
trace!("fd_tell(fd={:?}, newoffset={:#x?})", fd, newoffset);
|
||||||
|
|
||||||
let fd = dec_fd(fd);
|
let fd = dec_fd(fd);
|
||||||
let fd = match wasi_ctx
|
let mut fd = match wasi_ctx
|
||||||
.get_fd_entry(fd, host::__WASI_RIGHT_FD_TELL, 0)
|
.get_fd_entry(fd, host::__WASI_RIGHT_FD_TELL, 0)
|
||||||
.and_then(|fe| fe.fd_object.descriptor.as_file())
|
.and_then(|fe| fe.fd_object.descriptor.as_file())
|
||||||
{
|
{
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => return return_enc_errno(e),
|
Err(e) => return return_enc_errno(e),
|
||||||
};
|
};
|
||||||
let host_offset = match hostcalls_impl::fd_tell(fd) {
|
|
||||||
Ok(host_offset) => host_offset,
|
let host_offset = match fd
|
||||||
|
.seek(SeekFrom::Current(0))
|
||||||
|
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
|
||||||
|
{
|
||||||
|
Ok(offset) => offset,
|
||||||
Err(e) => return return_enc_errno(e),
|
Err(e) => return return_enc_errno(e),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -27,14 +27,6 @@ pub(crate) fn fd_pwrite(file: &File, buf: &[u8], offset: host::__wasi_filesize_t
|
|||||||
.map_err(|e| e.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
|
.map_err(|e| e.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fd_tell(file: &File) -> Result<u64> {
|
|
||||||
use nix::unistd::{lseek, Whence};
|
|
||||||
match lseek(file.as_raw_fd(), 0, Whence::SeekCur) {
|
|
||||||
Ok(newoffset) => Ok(newoffset as u64),
|
|
||||||
Err(e) => Err(host_impl::errno_from_nix(e.as_errno().unwrap())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn fd_fdstat_get(fd: &File) -> Result<host::__wasi_fdflags_t> {
|
pub(crate) fn fd_fdstat_get(fd: &File) -> Result<host::__wasi_fdflags_t> {
|
||||||
use nix::fcntl::{fcntl, OFlag, F_GETFL};
|
use nix::fcntl::{fcntl, OFlag, F_GETFL};
|
||||||
match fcntl(fd.as_raw_fd(), F_GETFL).map(OFlag::from_bits_truncate) {
|
match fcntl(fd.as_raw_fd(), F_GETFL).map(OFlag::from_bits_truncate) {
|
||||||
|
|||||||
@@ -46,10 +46,6 @@ pub(crate) fn fd_pwrite(file: &File, buf: &[u8], offset: host::__wasi_filesize_t
|
|||||||
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
|
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fd_tell(file: &File) -> Result<u64> {
|
|
||||||
unimplemented!("fd_tell")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn fd_fdstat_get(fd: &File) -> Result<host::__wasi_fdflags_t> {
|
pub(crate) fn fd_fdstat_get(fd: &File) -> Result<host::__wasi_fdflags_t> {
|
||||||
use winx::file::AccessRight;
|
use winx::file::AccessRight;
|
||||||
match winx::file::get_file_access_rights(fd.as_raw_handle())
|
match winx::file::get_file_access_rights(fd.as_raw_handle())
|
||||||
|
|||||||
Reference in New Issue
Block a user