1 // Copyright 2015 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.
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.
13 use sys::fd::FileDesc;
16 pub struct Stdout(());
17 pub struct Stderr(());
20 pub fn new() -> io::Result<Stdin> { Ok(Stdin(())) }
22 pub fn read(&self, data: &mut [u8]) -> io::Result<usize> {
23 let fd = FileDesc::new(libc::STDIN_FILENO);
24 let ret = fd.read(data);
31 pub fn new() -> io::Result<Stdout> { Ok(Stdout(())) }
33 pub fn write(&self, data: &[u8]) -> io::Result<usize> {
34 let fd = FileDesc::new(libc::STDOUT_FILENO);
35 let ret = fd.write(data);
40 pub fn flush(&self) -> io::Result<()> {
46 pub fn new() -> io::Result<Stderr> { Ok(Stderr(())) }
48 pub fn write(&self, data: &[u8]) -> io::Result<usize> {
49 let fd = FileDesc::new(libc::STDERR_FILENO);
50 let ret = fd.write(data);
55 pub fn flush(&self) -> io::Result<()> {
60 // FIXME: right now this raw stderr handle is used in a few places because
61 // std::io::stderr_raw isn't exposed, but once that's exposed this impl
63 impl io::Write for Stderr {
64 fn write(&mut self, data: &[u8]) -> io::Result<usize> {
65 Stderr::write(self, data)
68 fn flush(&mut self) -> io::Result<()> {
73 pub fn is_ebadf(err: &io::Error) -> bool {
74 err.raw_os_error() == Some(libc::EBADF as i32)
77 pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
79 pub fn panic_output() -> Option<impl io::Write> {