This commit is contained in:
Marcin Mielniczuk
2019-09-08 08:41:29 +02:00
committed by Jakub Konka
parent 438c693508
commit 57c19cf073
3 changed files with 11 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ use crate::sys::errno_from_ioerror;
use failure::Fail; use failure::Fail;
use std::fmt; use std::fmt;
use std::num::TryFromIntError; use std::num::TryFromIntError;
use std::convert::Infallible;
#[derive(Clone, Copy, Debug, Fail)] #[derive(Clone, Copy, Debug, Fail)]
pub enum WasiError { pub enum WasiError {
@@ -134,6 +135,12 @@ impl From<TryFromIntError> for Error {
} }
} }
impl From<Infallible> for Error {
fn from(_: Infallible) -> Self {
unreachable!()
}
}
#[cfg(windows)] #[cfg(windows)]
impl From<winx::winerror::WinError> for Error { impl From<winx::winerror::WinError> for Error {
fn from(err: winx::winerror::WinError) -> Self { fn from(err: winx::winerror::WinError) -> Self {

View File

@@ -178,6 +178,7 @@ pub(crate) fn filetype_from_nix(sflags: nix::sys::stat::SFlag) -> host::__wasi_f
pub(crate) fn filestat_from_nix( pub(crate) fn filestat_from_nix(
filestat: nix::sys::stat::FileStat, filestat: nix::sys::stat::FileStat,
) -> Result<host::__wasi_filestat_t> { ) -> Result<host::__wasi_filestat_t> {
use std::convert::TryFrom;
fn filestat_to_timestamp(secs: u64, nsecs: u64) -> Result<host::__wasi_timestamp_t> { fn filestat_to_timestamp(secs: u64, nsecs: u64) -> Result<host::__wasi_timestamp_t> {
secs.checked_mul(1_000_000_000) secs.checked_mul(1_000_000_000)
.and_then(|sec_nsec| sec_nsec.checked_add(nsecs)) .and_then(|sec_nsec| sec_nsec.checked_add(nsecs))
@@ -185,8 +186,8 @@ pub(crate) fn filestat_from_nix(
} }
let filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode); let filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode);
let dev = host::__wasi_device_t::from(filestat.st_dev); let dev = host::__wasi_device_t::try_from(filestat.st_dev)?;
let ino = host::__wasi_inode_t::from(filestat.st_ino); let ino = host::__wasi_inode_t::try_from(filestat.st_ino)?;
let st_atim = filestat_to_timestamp(filestat.st_atime as u64, filestat.st_atime_nsec as u64)?; let st_atim = filestat_to_timestamp(filestat.st_atime as u64, filestat.st_atime_nsec as u64)?;
let st_ctim = filestat_to_timestamp(filestat.st_ctime as u64, filestat.st_ctime_nsec as u64)?; let st_ctim = filestat_to_timestamp(filestat.st_ctime as u64, filestat.st_ctime_nsec as u64)?;
let st_mtim = filestat_to_timestamp(filestat.st_mtime as u64, filestat.st_mtime_nsec as u64)?; let st_mtim = filestat_to_timestamp(filestat.st_mtime as u64, filestat.st_mtime_nsec as u64)?;

View File

@@ -74,7 +74,7 @@ pub(crate) fn fd_advise(
| host::__WASI_ADVICE_NOREUSE | host::__WASI_ADVICE_NOREUSE
| host::__WASI_ADVICE_RANDOM | host::__WASI_ADVICE_RANDOM
| host::__WASI_ADVICE_NORMAL => {} | host::__WASI_ADVICE_NORMAL => {}
_ => return Err(host::__WASI_EINVAL), _ => return Err(Error::EINVAL),
} }
Ok(()) Ok(())