* Clean up fd_filestat_get implementation
This commit does 4 things:
* Adds `yanix::file::fstat`, a wrapper around `libc::fstat`.
* It essentially reverts 89fbde2 for Unix hosts -- in other words,
it brings back the use of `fstat` to obtain `libc::stat` from a
file descriptor, rather than relying on `std::fs::Metadata`. This
way, we reuse `host_impl::filestat_from_nix` in
`hostcalls_impl::fd_filestat_get` implementation rather than
unnecessarily duplicate code for converting filestats into
`__wasi_filestat_t`.
* Moves `crate::helpers::systemtime_to_timestamp` to Windows `host_impl`
module. It does the same thing with helpers which assist in converting
`std::fs::Metadata` into `__wasi_filestat_t`. This should retain symmetry
between *nix and Windows impls.
* Makes timestamp conversions in `host_impl::filestat_from_nix` fallible.
* Backport changes to snapshot0
* Signal no overflow with `from` rather than `as` cast
11 lines
321 B
Rust
11 lines
321 B
Rust
use crate::{Error, Result};
|
|
use std::str;
|
|
|
|
/// Creates not-owned WASI path from byte slice.
|
|
///
|
|
/// NB WASI spec requires bytes to be valid UTF-8. Otherwise,
|
|
/// `__WASI_ERRNO_ILSEQ` error is returned.
|
|
pub(crate) fn path_from_slice<'a>(s: &'a [u8]) -> Result<&'a str> {
|
|
str::from_utf8(s).map_err(|_| Error::EILSEQ)
|
|
}
|