alnyan/yggdrasil: implement Stdin
This commit is contained in:
@@ -4,7 +4,8 @@ pub(crate) mod io;
|
||||
|
||||
#[stable(feature = "yggdrasil_platform", since = "1.70.0")]
|
||||
pub use yggdrasil_rt::{
|
||||
io::{MountOptions, UnmountOptions},
|
||||
io::{FileMode, MountOptions, OpenOptions, UnmountOptions},
|
||||
sys::open,
|
||||
Error,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use crate::io;
|
||||
use crate::io::{IoSlice, IoSliceMut};
|
||||
use crate::sys::cvt_io;
|
||||
use yggdrasil_rt::io::RawFd;
|
||||
|
||||
// const FILENO_STDIN: i32 = 0;
|
||||
|
||||
pub struct Stdin;
|
||||
pub struct Stdout;
|
||||
pub struct Stderr;
|
||||
@@ -27,32 +26,23 @@ impl Stderr {
|
||||
}
|
||||
|
||||
impl io::Read for Stdin {
|
||||
fn read(&mut self, _data: &mut [u8]) -> io::Result<usize> {
|
||||
todo!();
|
||||
// self.read_vectored(&mut [IoSliceMut::new(data)])
|
||||
fn read(&mut self, data: &mut [u8]) -> io::Result<usize> {
|
||||
cvt_io(unsafe { yggdrasil_rt::sys::read(RawFd::STDIN, data) })
|
||||
}
|
||||
|
||||
fn read_vectored(&mut self, _data: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
|
||||
todo!()
|
||||
// Ok(0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_read_vectored(&self) -> bool {
|
||||
todo!()
|
||||
// true
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Write for Stdout {
|
||||
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
||||
match unsafe { yggdrasil_rt::sys::write(RawFd::STDOUT, data) } {
|
||||
Ok(len) => Ok(len),
|
||||
Err(_) => Err(io::const_io_error!(
|
||||
io::ErrorKind::Uncategorized,
|
||||
"Stdout is not able to print"
|
||||
)),
|
||||
}
|
||||
cvt_io(unsafe { yggdrasil_rt::sys::write(RawFd::STDOUT, data) })
|
||||
}
|
||||
|
||||
fn write_vectored(&mut self, _data: &[IoSlice<'_>]) -> io::Result<usize> {
|
||||
@@ -71,44 +61,24 @@ impl io::Write for Stdout {
|
||||
|
||||
impl io::Write for Stderr {
|
||||
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
||||
match unsafe { yggdrasil_rt::sys::write(RawFd::STDERR, data) } {
|
||||
Ok(len) => Ok(len),
|
||||
Err(_) => Err(io::const_io_error!(
|
||||
io::ErrorKind::Uncategorized,
|
||||
"Stderr is not able to print"
|
||||
)),
|
||||
}
|
||||
cvt_io(unsafe { yggdrasil_rt::sys::write(RawFd::STDERR, data) })
|
||||
}
|
||||
|
||||
fn write_vectored(&mut self, _data: &[IoSlice<'_>]) -> io::Result<usize> {
|
||||
todo!();
|
||||
// let len;
|
||||
|
||||
// unsafe { len = abi::write(1, data.as_ptr() as *const u8, data.len()) }
|
||||
|
||||
// if len < 0 {
|
||||
// Err(io::const_io_error!(
|
||||
// io::ErrorKind::Uncategorized,
|
||||
// "Stdout is not able to print"
|
||||
// ))
|
||||
// } else {
|
||||
// Ok(len as usize)
|
||||
// }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_write_vectored(&self) -> bool {
|
||||
false
|
||||
// true
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
todo!()
|
||||
// Ok(())
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub const STDIN_BUF_SIZE: usize = 0;
|
||||
pub const STDIN_BUF_SIZE: usize = 64;
|
||||
|
||||
pub fn is_ebadf(_err: &io::Error) -> bool {
|
||||
true
|
||||
|
||||
Reference in New Issue
Block a user