Merge remote-tracking branch 'origin/main' into pch/wasi_common_cap_std
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
// TODO it might worth re-investigating the suitability of this type on Windows.
|
||||
|
||||
use super::{fd, AsFile};
|
||||
use crate::handle::{Fdflags, Filetype, Handle, HandleRights, Rights, RightsExt, Size};
|
||||
use crate::handle::{Fdflags, Filestat, Filetype, Handle, HandleRights, Rights, RightsExt, Size};
|
||||
use crate::sandboxed_tty_writer::SandboxedTTYWriter;
|
||||
use crate::{Error, Result};
|
||||
use std::any::Any;
|
||||
@@ -65,6 +65,9 @@ impl Handle for Stdin {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn filestat_get(&self) -> Result<Filestat> {
|
||||
fd::filestat_get(&*self.as_file()?)
|
||||
}
|
||||
fn read_vectored(&self, iovs: &mut [io::IoSliceMut]) -> Result<usize> {
|
||||
let nread = io::stdin().read_vectored(iovs)?;
|
||||
Ok(nread)
|
||||
@@ -111,6 +114,9 @@ impl Handle for Stdout {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn filestat_get(&self) -> Result<Filestat> {
|
||||
fd::filestat_get(&*self.as_file()?)
|
||||
}
|
||||
fn write_vectored(&self, iovs: &[io::IoSlice]) -> Result<usize> {
|
||||
// lock for the duration of the scope
|
||||
let stdout = io::stdout();
|
||||
@@ -165,6 +171,9 @@ impl Handle for Stderr {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn filestat_get(&self) -> Result<Filestat> {
|
||||
fd::filestat_get(&*self.as_file()?)
|
||||
}
|
||||
fn write_vectored(&self, iovs: &[io::IoSlice]) -> Result<usize> {
|
||||
// Always sanitize stderr, even if it's not directly connected to a tty,
|
||||
// because stderr is meant for diagnostics rather than binary output,
|
||||
|
||||
@@ -9,7 +9,8 @@ pub(crate) mod poll;
|
||||
pub(crate) mod stdio;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "linux")] {
|
||||
if #[cfg(any(target_os = "linux",
|
||||
target_os = "android"))] {
|
||||
mod linux;
|
||||
use linux as sys_impl;
|
||||
} else if #[cfg(target_os = "emscripten")] {
|
||||
|
||||
@@ -36,9 +36,15 @@ impl Dir {
|
||||
}
|
||||
|
||||
/// Set the position of the directory stream, see `seekdir(3)`.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub fn seek(&mut self, loc: SeekLoc) {
|
||||
unsafe { libc::seekdir(self.0.as_ptr(), loc.0) }
|
||||
// https://github.com/rust-lang/libc/pull/1996
|
||||
#[cfg(not(target_os = "android"))]
|
||||
use libc::seekdir;
|
||||
#[cfg(target_os = "android")]
|
||||
extern "C" {
|
||||
fn seekdir(dirp: *mut libc::DIR, loc: libc::c_long);
|
||||
}
|
||||
unsafe { seekdir(self.0.as_ptr(), loc.0) }
|
||||
}
|
||||
|
||||
/// Reset directory stream, see `rewinddir(3)`.
|
||||
@@ -50,10 +56,16 @@ impl Dir {
|
||||
///
|
||||
/// If this location is given to `Dir::seek`, the entries up to the previously returned
|
||||
/// will be omitted and the iteration will start from the currently pending directory entry.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
#[allow(dead_code)]
|
||||
pub fn tell(&self) -> SeekLoc {
|
||||
let loc = unsafe { libc::telldir(self.0.as_ptr()) };
|
||||
#[cfg(not(target_os = "android"))]
|
||||
use libc::telldir;
|
||||
#[cfg(target_os = "android")]
|
||||
extern "C" {
|
||||
fn telldir(dirp: *mut libc::DIR) -> libc::c_long;
|
||||
}
|
||||
// https://github.com/rust-lang/libc/pull/1996
|
||||
let loc = unsafe { telldir(self.0.as_ptr()) };
|
||||
SeekLoc(loc)
|
||||
}
|
||||
|
||||
@@ -93,11 +105,9 @@ impl Entry {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct SeekLoc(pub(crate) libc::c_long);
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
impl SeekLoc {
|
||||
pub fn to_raw(&self) -> i64 {
|
||||
self.0.into()
|
||||
|
||||
@@ -90,11 +90,26 @@ bitflags! {
|
||||
const WRONLY = libc::O_WRONLY;
|
||||
const RDWR = libc::O_RDWR;
|
||||
#[cfg(any(target_os = "linux",
|
||||
target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "wasi",
|
||||
target_os = "emscripten"))]
|
||||
const RSYNC = libc::O_RSYNC;
|
||||
const RSYNC = {
|
||||
// Have to use cfg_if: https://github.com/bitflags/bitflags/issues/137
|
||||
cfg_if! {
|
||||
if #[cfg(any(target_os = "linux",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "wasi",
|
||||
target_os = "emscripten"))] {
|
||||
libc::O_RSYNC
|
||||
} else if #[cfg(target_os = "android")] {
|
||||
// Android defines O_RSYNC as O_SYNC
|
||||
libc::O_SYNC
|
||||
}
|
||||
}
|
||||
};
|
||||
const SYNC = libc::O_SYNC;
|
||||
const TRUNC = libc::O_TRUNC;
|
||||
#[cfg(any(target_os = "linux",
|
||||
|
||||
@@ -53,5 +53,8 @@ pub fn utimensat(
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
super::utimesat::utimesat(dirfd, path, atime, mtime, symlink_nofollow)
|
||||
#[cfg(not(target_os = "android"))]
|
||||
return super::utimesat::utimesat(dirfd, path, atime, mtime, symlink_nofollow);
|
||||
#[cfg(target_os = "android")]
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
@@ -2,4 +2,5 @@ pub(crate) mod dir;
|
||||
pub(crate) mod fadvise;
|
||||
pub(crate) mod file;
|
||||
pub(crate) mod filetime;
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub(crate) mod utimesat;
|
||||
|
||||
Reference in New Issue
Block a user