]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/cloudabi/stdio.rs
Permit use of mem::uninitialized via allow(deprecated)
[rust.git] / src / libstd / sys / cloudabi / stdio.rs
1 use crate::io;
2 use crate::sys::cloudabi::abi;
3
4 pub struct Stdin(());
5 pub struct Stdout(());
6 pub struct Stderr(());
7
8 impl Stdin {
9     pub fn new() -> io::Result<Stdin> {
10         Ok(Stdin(()))
11     }
12 }
13
14 impl io::Read for Stdin {
15     fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
16         Ok(0)
17     }
18 }
19
20 impl Stdout {
21     pub fn new() -> io::Result<Stdout> {
22         Ok(Stdout(()))
23     }
24 }
25
26 impl io::Write for Stdout {
27     fn write(&mut self, _buf: &[u8]) -> io::Result<usize> {
28         Err(io::Error::new(
29             io::ErrorKind::BrokenPipe,
30             "Stdout is not connected to any output in this environment",
31         ))
32     }
33
34     fn flush(&mut self) -> io::Result<()> {
35         Ok(())
36     }
37 }
38
39 impl Stderr {
40     pub fn new() -> io::Result<Stderr> {
41         Ok(Stderr(()))
42     }
43 }
44
45 impl io::Write for Stderr {
46     fn write(&mut self, _buf: &[u8]) -> io::Result<usize> {
47         Err(io::Error::new(
48             io::ErrorKind::BrokenPipe,
49             "Stderr is not connected to any output in this environment",
50         ))
51     }
52
53     fn flush(&mut self) -> io::Result<()> {
54         Ok(())
55     }
56 }
57
58 pub fn is_ebadf(err: &io::Error) -> bool {
59     err.raw_os_error() == Some(abi::errno::BADF as i32)
60 }
61
62 pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
63
64 pub fn panic_output() -> Option<impl io::Write> {
65     Stderr::new().ok()
66 }