alnyan/yggdrasil: more terminal options
This commit is contained in:
@@ -1,6 +1,64 @@
|
||||
#![stable(feature = "os_fd", since = "1.66.0")]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::mem::MaybeUninit;
|
||||
use crate::sys::cvt_io;
|
||||
use yggdrasil_rt::sys as syscall;
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub use yggdrasil_rt::io::{
|
||||
DeviceRequest, TerminalInputOptions, TerminalLineOptions, TerminalOptions,
|
||||
TerminalOutputOptions,
|
||||
};
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub trait FdDeviceRequest {
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
unsafe fn device_request(&self, req: &mut DeviceRequest) -> crate::io::Result<()>;
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
impl<T: AsRawFd> FdDeviceRequest for T {
|
||||
unsafe fn device_request(&self, req: &mut DeviceRequest) -> crate::io::Result<()> {
|
||||
cvt_io(syscall::device_request(self.as_raw_fd(), req))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub unsafe fn set_terminal_options<F: raw::AsRawFd>(
|
||||
fd: F,
|
||||
opt: TerminalOptions,
|
||||
) -> crate::io::Result<()> {
|
||||
let mut req = DeviceRequest::SetTerminalOptions(opt);
|
||||
cvt_io(syscall::device_request(fd.as_raw_fd(), &mut req))
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub unsafe fn get_terminal_options<F: raw::AsRawFd>(fd: F) -> crate::io::Result<TerminalOptions> {
|
||||
let mut req = DeviceRequest::GetTerminalOptions(MaybeUninit::uninit());
|
||||
cvt_io(syscall::device_request(fd.as_raw_fd(), &mut req))?;
|
||||
let DeviceRequest::GetTerminalOptions(opt) = req else {
|
||||
unreachable!();
|
||||
};
|
||||
Ok(opt.assume_init())
|
||||
}
|
||||
|
||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||
pub unsafe fn update_terminal_options<
|
||||
F: raw::AsRawFd,
|
||||
M: Fn(TerminalOptions) -> TerminalOptions,
|
||||
>(
|
||||
fd: F,
|
||||
mutator: M,
|
||||
) -> crate::io::Result<TerminalOptions> {
|
||||
let fd = fd.as_raw_fd();
|
||||
let old = get_terminal_options(fd)?;
|
||||
let new = mutator(old);
|
||||
set_terminal_options(fd, new)?;
|
||||
Ok(old)
|
||||
}
|
||||
|
||||
mod net {
|
||||
use crate::os::yggdrasil::io::OwnedFd;
|
||||
use crate::os::yggdrasil::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
||||
@@ -49,10 +107,31 @@ mod net {
|
||||
impl_into_raw_fd! { TcpStream TcpListener UdpSocket }
|
||||
}
|
||||
|
||||
pub mod raw {
|
||||
#[stable(feature = "os_fd", since = "1.66.0")]
|
||||
pub(crate) mod raw {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub type RawFd = yggdrasil_rt::io::RawFd;
|
||||
|
||||
macro_rules! stdio_impl_as_raw_fd {
|
||||
($($ty:ty => $n:expr),*) => {$(
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawFd for $ty {
|
||||
#[inline]
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
$n
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawFd for &$ty {
|
||||
#[inline]
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
$n
|
||||
}
|
||||
}
|
||||
)*};
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub trait AsRawFd {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@@ -91,6 +170,12 @@ pub mod raw {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
stdio_impl_as_raw_fd!(
|
||||
crate::io::Stdin => RawFd::STDIN,
|
||||
crate::io::Stdout => RawFd::STDOUT,
|
||||
crate::io::Stderr => RawFd::STDERR
|
||||
);
|
||||
}
|
||||
|
||||
pub mod owned {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![stable(feature = "os", since = "1.0.0")]
|
||||
|
||||
pub(crate) mod io;
|
||||
pub mod io;
|
||||
pub mod process;
|
||||
|
||||
#[unstable(feature = "yggdrasil_raw_fd", issue = "none")]
|
||||
|
||||
@@ -321,7 +321,7 @@ impl Command {
|
||||
|
||||
let options = SpawnOptions { program, arguments, environment, optional: &optional };
|
||||
|
||||
let pid = cvt_io(unsafe { yggdrasil_rt::sys::spawn(&options) })?;
|
||||
let pid = cvt_io(unsafe { yggdrasil_rt::sys::spawn_process(&options) })?;
|
||||
|
||||
Ok(Process { pid })
|
||||
}
|
||||
|
||||
+1
-1
Submodule yggdrasil-rt updated: a882ffa028...f00ecdb926
Reference in New Issue
Block a user