xref: /drstd/src/std/sys/solid/stdio.rs (revision 86982c5e9b2eaa583327251616ee822c36288824)
1 use super::abi;
2 use crate::std::io;
3 
4 pub struct Stdin;
5 pub struct Stdout;
6 pub struct Stderr;
7 struct PanicOutput;
8 
9 impl Stdin {
10     pub const fn new() -> Stdin {
11         Stdin
12     }
13 }
14 
15 impl io::Read for Stdin {
16     fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
17         Ok(0)
18     }
19 }
20 
21 impl Stdout {
22     pub const fn new() -> Stdout {
23         Stdout
24     }
25 }
26 
27 impl io::Write for Stdout {
28     fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
29         unsafe { abi::SOLID_LOG_write(buf.as_ptr(), buf.len()) };
30         Ok(buf.len())
31     }
32 
33     fn flush(&mut self) -> io::Result<()> {
34         Ok(())
35     }
36 }
37 
38 impl Stderr {
39     pub const fn new() -> Stderr {
40         Stderr
41     }
42 }
43 
44 impl io::Write for Stderr {
45     fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
46         unsafe { abi::SOLID_LOG_write(buf.as_ptr(), buf.len()) };
47         Ok(buf.len())
48     }
49 
50     fn flush(&mut self) -> io::Result<()> {
51         Ok(())
52     }
53 }
54 
55 impl PanicOutput {
56     pub const fn new() -> PanicOutput {
57         PanicOutput
58     }
59 }
60 
61 impl io::Write for PanicOutput {
62     fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
63         unsafe { abi::SOLID_LOG_write(buf.as_ptr(), buf.len()) };
64         Ok(buf.len())
65     }
66 
67     fn flush(&mut self) -> io::Result<()> {
68         Ok(())
69     }
70 }
71 
72 pub const STDIN_BUF_SIZE: usize = 0;
73 
74 pub fn is_ebadf(_err: &io::Error) -> bool {
75     true
76 }
77 
78 pub fn panic_output() -> Option<impl io::Write> {
79     Some(PanicOutput::new())
80 }
81