]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/cloudabi/stdio.rs
1d7344f921c9d564d30bac0c09f86bcf7b682995
[rust.git] / src / libstd / sys / cloudabi / 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::cloudabi::abi;
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, _: &mut [u8]) -> io::Result<usize> {
24         Ok(0)
25     }
26 }
27
28 impl Stdout {
29     pub fn new() -> io::Result<Stdout> {
30         Ok(Stdout(()))
31     }
32
33     pub fn write(&self, _: &[u8]) -> io::Result<usize> {
34         Err(io::Error::new(
35             io::ErrorKind::BrokenPipe,
36             "Stdout is not connected to any output in this environment",
37         ))
38     }
39
40     pub fn flush(&self) -> io::Result<()> {
41         Ok(())
42     }
43 }
44
45 impl Stderr {
46     pub fn new() -> io::Result<Stderr> {
47         Ok(Stderr(()))
48     }
49
50     pub fn write(&self, _: &[u8]) -> io::Result<usize> {
51         Err(io::Error::new(
52             io::ErrorKind::BrokenPipe,
53             "Stderr is not connected to any output in this environment",
54         ))
55     }
56
57     pub fn flush(&self) -> io::Result<()> {
58         Ok(())
59     }
60 }
61
62 // FIXME: right now this raw stderr handle is used in a few places because
63 //        std::io::stderr_raw isn't exposed, but once that's exposed this impl
64 //        should go away
65 impl io::Write for Stderr {
66     fn write(&mut self, data: &[u8]) -> io::Result<usize> {
67         Stderr::write(self, data)
68     }
69
70     fn flush(&mut self) -> io::Result<()> {
71         Stderr::flush(self)
72     }
73 }
74
75 pub fn is_ebadf(err: &io::Error) -> bool {
76     err.raw_os_error() == Some(abi::errno::BADF as i32)
77 }
78
79 pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
80
81 pub fn stderr_prints_nothing() -> bool {
82     false
83 }