diff options
| author | joboet <jonasboettiger@icloud.com> | 2025-02-09 18:42:07 +0100 |
|---|---|---|
| committer | joboet <jonasboettiger@icloud.com> | 2025-03-09 23:42:13 +0100 |
| commit | c52e0596c5ef1d68bf0f283342fdb05db63248f9 (patch) | |
| tree | 028fcf26c4fd60709226ac4ddf1412f3d94148a7 /library/std/src/sys/stdio/solid.rs | |
| parent | 3ea711f17e3946ac3f4df11691584e2c56b4b0cf (diff) | |
| download | rust-c52e0596c5ef1d68bf0f283342fdb05db63248f9.tar.gz rust-c52e0596c5ef1d68bf0f283342fdb05db63248f9.zip | |
std: move stdio to `sys`
As per #117276, this moves the platform definitions of `Stdout` and friends into `sys`. This PR also unifies the UNIX and Hermit implementations and moves the `__rust_print_err` function needed by libunwind on SGX into the dedicated module for such helper functions.
Diffstat (limited to 'library/std/src/sys/stdio/solid.rs')
| -rw-r--r-- | library/std/src/sys/stdio/solid.rs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/library/std/src/sys/stdio/solid.rs b/library/std/src/sys/stdio/solid.rs new file mode 100644 index 00000000000..a2ff4bb212f --- /dev/null +++ b/library/std/src/sys/stdio/solid.rs @@ -0,0 +1,80 @@ +use crate::io; +use crate::sys::pal::abi; + +pub struct Stdin; +pub struct Stdout; +pub struct Stderr; +struct PanicOutput; + +impl Stdin { + pub const fn new() -> Stdin { + Stdin + } +} + +impl io::Read for Stdin { + fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> { + Ok(0) + } +} + +impl Stdout { + pub const fn new() -> Stdout { + Stdout + } +} + +impl io::Write for Stdout { + fn write(&mut self, buf: &[u8]) -> io::Result<usize> { + unsafe { abi::SOLID_LOG_write(buf.as_ptr(), buf.len()) }; + Ok(buf.len()) + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +impl Stderr { + pub const fn new() -> Stderr { + Stderr + } +} + +impl io::Write for Stderr { + fn write(&mut self, buf: &[u8]) -> io::Result<usize> { + unsafe { abi::SOLID_LOG_write(buf.as_ptr(), buf.len()) }; + Ok(buf.len()) + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +impl PanicOutput { + pub const fn new() -> PanicOutput { + PanicOutput + } +} + +impl io::Write for PanicOutput { + fn write(&mut self, buf: &[u8]) -> io::Result<usize> { + unsafe { abi::SOLID_LOG_write(buf.as_ptr(), buf.len()) }; + Ok(buf.len()) + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +pub const STDIN_BUF_SIZE: usize = 0; + +pub fn is_ebadf(_err: &io::Error) -> bool { + true +} + +pub fn panic_output() -> Option<impl io::Write> { + Some(PanicOutput::new()) +} |
