Files
riscv64-kernel/crates/std/src/io.rs
2026-03-17 21:33:34 +01:00

72 lines
1.9 KiB
Rust

use crate::fs::File;
use io::IoBase;
pub use io::Read;
pub use io::Seek;
pub use io::SeekFrom;
pub use io::Write;
pub struct Stdin;
impl IoBase for Stdin {
type Error = ();
}
impl Read for Stdin {
fn read(&mut self, buf: &mut [u8]) -> core::result::Result<usize, Self::Error> {
unsafe { File::from_raw_fd(0).read(buf) }
}
}
pub fn stdin() -> Stdin {
Stdin
}
pub type Result<T> = core::result::Result<T, Error>;
pub(super) struct Repr();
// Part took from the real std
#[rustc_macro_transparency = "semiopaque"]
#[unstable(feature = "io_const_error", issue = "133448")]
#[allow_internal_unstable(hint_must_use, io_const_error_internals)]
pub macro const_error($kind:expr, $message:expr $(,)?) {
crate::io::Error::new()
}
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Error {
repr: Repr,
}
impl Error {
pub const fn new() -> Self {
Self { repr: Repr() }
}
}
#[allow(dead_code)]
impl Error {
pub(crate) const INVALID_UTF8: Self =
const_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8");
pub(crate) const READ_EXACT_EOF: Self =
const_error!(ErrorKind::UnexpectedEof, "failed to fill whole buffer");
pub(crate) const UNKNOWN_THREAD_COUNT: Self = const_error!(
ErrorKind::NotFound,
"the number of hardware threads is not known for the target platform",
);
pub(crate) const UNSUPPORTED_PLATFORM: Self =
const_error!(ErrorKind::Unsupported, "operation not supported on this platform");
pub(crate) const WRITE_ALL_EOF: Self =
const_error!(ErrorKind::WriteZero, "failed to write whole buffer");
pub(crate) const ZERO_TIMEOUT: Self =
const_error!(ErrorKind::InvalidInput, "cannot set a 0 duration timeout");
pub(crate) const NO_ADDRESSES: Self =
const_error!(ErrorKind::InvalidInput, "could not resolve to any addresses");
}