]>
Commit | Line | Data |
---|---|---|
c34b1796 AL |
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. | |
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 | ||
c34b1796 AL |
11 | use io; |
12 | use libc; | |
13 | use sys::fd::FileDesc; | |
14 | ||
15 | pub struct Stdin(()); | |
16 | pub struct Stdout(()); | |
17 | pub struct Stderr(()); | |
18 | ||
19 | impl Stdin { | |
62682a34 | 20 | pub fn new() -> io::Result<Stdin> { Ok(Stdin(())) } |
c34b1796 AL |
21 | |
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); | |
25 | fd.into_raw(); | |
e9174d1e | 26 | ret |
c34b1796 | 27 | } |
54a0048b SL |
28 | |
29 | pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> { | |
30 | let fd = FileDesc::new(libc::STDIN_FILENO); | |
31 | let ret = fd.read_to_end(buf); | |
32 | fd.into_raw(); | |
33 | ret | |
34 | } | |
c34b1796 AL |
35 | } |
36 | ||
37 | impl Stdout { | |
62682a34 | 38 | pub fn new() -> io::Result<Stdout> { Ok(Stdout(())) } |
c34b1796 AL |
39 | |
40 | pub fn write(&self, data: &[u8]) -> io::Result<usize> { | |
41 | let fd = FileDesc::new(libc::STDOUT_FILENO); | |
42 | let ret = fd.write(data); | |
43 | fd.into_raw(); | |
e9174d1e | 44 | ret |
c34b1796 AL |
45 | } |
46 | } | |
47 | ||
48 | impl Stderr { | |
62682a34 | 49 | pub fn new() -> io::Result<Stderr> { Ok(Stderr(())) } |
c34b1796 AL |
50 | |
51 | pub fn write(&self, data: &[u8]) -> io::Result<usize> { | |
52 | let fd = FileDesc::new(libc::STDERR_FILENO); | |
53 | let ret = fd.write(data); | |
54 | fd.into_raw(); | |
e9174d1e | 55 | ret |
c34b1796 AL |
56 | } |
57 | } | |
58 | ||
59 | // FIXME: right now this raw stderr handle is used in a few places because | |
60 | // std::io::stderr_raw isn't exposed, but once that's exposed this impl | |
61 | // should go away | |
62 | impl io::Write for Stderr { | |
63 | fn write(&mut self, data: &[u8]) -> io::Result<usize> { | |
64 | Stderr::write(self, data) | |
65 | } | |
66 | fn flush(&mut self) -> io::Result<()> { Ok(()) } | |
67 | } | |
c30ab7b3 SL |
68 | |
69 | pub const EBADF_ERR: i32 = ::libc::EBADF as i32; | |
70 | pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; |