]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/vxworks/stdio.rs
Remove result type from raw standard streams constructors
[rust.git] / library / std / src / sys / vxworks / stdio.rs
1 use crate::io;
2 use crate::sys::fd::FileDesc;
3
4 pub struct Stdin(());
5 pub struct Stdout(());
6 pub struct Stderr(());
7
8 impl Stdin {
9     pub fn new() -> Stdin {
10         Stdin(())
11     }
12 }
13
14 impl io::Read for Stdin {
15     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
16         let fd = FileDesc::new(libc::STDIN_FILENO);
17         let ret = fd.read(buf);
18         fd.into_raw(); // do not close this FD
19         ret
20     }
21 }
22
23 impl Stdout {
24     pub fn new() -> Stdout {
25         Stdout(())
26     }
27 }
28
29 impl io::Write for Stdout {
30     fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
31         let fd = FileDesc::new(libc::STDOUT_FILENO);
32         let ret = fd.write(buf);
33         fd.into_raw(); // do not close this FD
34         ret
35     }
36
37     fn flush(&mut self) -> io::Result<()> {
38         Ok(())
39     }
40 }
41
42 impl Stderr {
43     pub fn new() -> Stderr {
44         Stderr(())
45     }
46 }
47
48 impl io::Write for Stderr {
49     fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
50         let fd = FileDesc::new(libc::STDERR_FILENO);
51         let ret = fd.write(buf);
52         fd.into_raw(); // do not close this FD
53         ret
54     }
55
56     fn flush(&mut self) -> io::Result<()> {
57         Ok(())
58     }
59 }
60
61 pub fn is_ebadf(err: &io::Error) -> bool {
62     err.raw_os_error() == Some(libc::EBADF as i32)
63 }
64
65 pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
66
67 pub fn panic_output() -> Option<impl io::Write> {
68     Some(Stderr::new())
69 }