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