]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/sgx/stdio.rs
540599a35964cb2e33ddf48339f7e8f309f2ae8a
[rust.git] / src / libstd / sys / sgx / stdio.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use io;
12 use sys::unsupported;
13
14 pub struct Stdin;
15 pub struct Stdout;
16 pub struct Stderr;
17
18 impl Stdin {
19     pub fn new() -> io::Result<Stdin> {
20         Ok(Stdin)
21     }
22
23     pub fn read(&self, _data: &mut [u8]) -> io::Result<usize> {
24         unsupported()
25     }
26 }
27
28 impl Stdout {
29     pub fn new() -> io::Result<Stdout> {
30         Ok(Stdout)
31     }
32
33     pub fn write(&self, _data: &[u8]) -> io::Result<usize> {
34         unsupported()
35     }
36
37     pub fn flush(&self) -> io::Result<()> {
38         Ok(())
39     }
40 }
41
42 impl Stderr {
43     pub fn new() -> io::Result<Stderr> {
44         Ok(Stderr)
45     }
46
47     pub fn write(&self, _data: &[u8]) -> io::Result<usize> {
48         unsupported()
49     }
50
51     pub fn flush(&self) -> io::Result<()> {
52         Ok(())
53     }
54 }
55
56 impl io::Write for Stderr {
57     fn write(&mut self, data: &[u8]) -> io::Result<usize> {
58         (&*self).write(data)
59     }
60     fn flush(&mut self) -> io::Result<()> {
61         (&*self).flush()
62     }
63 }
64
65 pub const STDIN_BUF_SIZE: usize = 0;
66
67 pub fn is_ebadf(_err: &io::Error) -> bool {
68     true
69 }
70
71 pub fn panic_output() -> Option<impl io::Write> {
72     super::abi::panic::SgxPanicOutput::new()
73 }