This commit merges [CraneStation/wasi-common] repo as a subdir of this repo while preserving **all** of git history. There is an initiative to pull `wasi-common` into [CraneStation/wasmtime], and [CraneStation/wasmtime] becoming a monorepo. This came about for several reasons with a common theme of convenience, namely, having a monorepo: 1. cleans up the problem of dependencies (as we have seen first hand with dependabot enabled, it can cause some grief) 2. completely removes the problem of syncing the closely dependent repos (e.g., updating `wasi-common` with say a bugfix generally implies creating a "sync" commit for pulling in the changes into the "parent" repo, in this case, `wasmtime`) 3. mainly for the two reasons above, makes publishing to crates.io easier 4. hopefully streamlines the process of getting the community involved in contributing to `wasi-common` as now everything is one place [CraneStation/wasi-common]: https://github.com/CraneStation/wasi-common [CraneStation/wasmtime]: https://github.com/CraneStation/wasmtime
83 lines
2.8 KiB
Rust
83 lines
2.8 KiB
Rust
pub(crate) mod hostcalls_impl;
|
|
pub(crate) mod osfile;
|
|
|
|
pub(crate) mod fdentry_impl {
|
|
use crate::{sys::host_impl, Result};
|
|
use std::os::unix::prelude::AsRawFd;
|
|
|
|
pub(crate) unsafe fn isatty(fd: &impl AsRawFd) -> Result<bool> {
|
|
let res = libc::isatty(fd.as_raw_fd());
|
|
if res == 1 {
|
|
// isatty() returns 1 if fd is an open file descriptor referring to a terminal...
|
|
Ok(true)
|
|
} else {
|
|
// ... otherwise 0 is returned, and errno is set to indicate the error.
|
|
match nix::errno::Errno::last() {
|
|
nix::errno::Errno::ENOTTY => Ok(false),
|
|
x => Err(host_impl::errno_from_nix(x)),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) mod host_impl {
|
|
use super::super::host_impl::dirent_filetype_from_host;
|
|
use crate::{wasi, Result};
|
|
|
|
pub(crate) const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_SYNC;
|
|
|
|
pub(crate) fn dirent_from_host(
|
|
host_entry: &nix::libc::dirent,
|
|
) -> Result<wasi::__wasi_dirent_t> {
|
|
let mut entry = unsafe { std::mem::zeroed::<wasi::__wasi_dirent_t>() };
|
|
let d_type = dirent_filetype_from_host(host_entry)?;
|
|
entry.d_ino = host_entry.d_ino;
|
|
entry.d_next = host_entry.d_seekoff;
|
|
entry.d_namlen = u32::from(host_entry.d_namlen);
|
|
entry.d_type = d_type;
|
|
Ok(entry)
|
|
}
|
|
}
|
|
|
|
pub(crate) mod fs_helpers {
|
|
use cfg_if::cfg_if;
|
|
|
|
pub(crate) fn utime_now() -> libc::c_long {
|
|
cfg_if! {
|
|
if #[cfg(any(
|
|
target_os = "macos",
|
|
target_os = "freebsd",
|
|
target_os = "ios",
|
|
target_os = "dragonfly"
|
|
))] {
|
|
-1
|
|
} else if #[cfg(target_os = "openbsd")] {
|
|
// https://github.com/openbsd/src/blob/master/sys/sys/stat.h#L187
|
|
-2
|
|
} else if #[cfg(target_os = "netbsd" )] {
|
|
// http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/stat.h?rev=1.69&content-type=text/x-cvsweb-markup&only_with_tag=MAIN
|
|
1_073_741_823
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) fn utime_omit() -> libc::c_long {
|
|
cfg_if! {
|
|
if #[cfg(any(
|
|
target_os = "macos",
|
|
target_os = "freebsd",
|
|
target_os = "ios",
|
|
target_os = "dragonfly"
|
|
))] {
|
|
-2
|
|
} else if #[cfg(target_os = "openbsd")] {
|
|
// https://github.com/openbsd/src/blob/master/sys/sys/stat.h#L187
|
|
-1
|
|
} else if #[cfg(target_os = "netbsd")] {
|
|
// http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/stat.h?rev=1.69&content-type=text/x-cvsweb-markup&only_with_tag=MAIN
|
|
1_073_741_822
|
|
}
|
|
}
|
|
}
|
|
}
|