Skip to content

Commit dd5e3f6

Browse files
committed
---
yaml --- r: 95318 b: refs/heads/dist-snap c: edf4c16 h: refs/heads/master v: v3
1 parent b67d964 commit dd5e3f6

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: b509f7905a578663d57121973b4a9a6b619341c2
9+
refs/heads/dist-snap: edf4c16997af6af08ef734ad34eccc5aa279595a
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2013 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 libc;
12+
use option::Option;
13+
use rt::io::{Reader, Writer};
14+
use super::file;
15+
16+
/// Creates a new handle to the stdin of this process
17+
pub fn stdin() -> StdIn { StdIn::new() }
18+
/// Creates a new handle to the stdout of this process
19+
pub fn stdout() -> StdOut { StdOut::new(libc::STDOUT_FILENO) }
20+
/// Creates a new handle to the stderr of this process
21+
pub fn stderr() -> StdOut { StdOut::new(libc::STDERR_FILENO) }
22+
23+
pub fn print(s: &str) {
24+
stdout().write(s.as_bytes())
25+
}
26+
27+
pub fn println(s: &str) {
28+
let mut out = stdout();
29+
out.write(s.as_bytes());
30+
out.write(['\n' as u8]);
31+
}
32+
33+
pub struct StdIn {
34+
priv fd: file::FileDesc
35+
}
36+
37+
impl StdIn {
38+
/// Duplicates the stdin file descriptor, returning an io::Reader
39+
#[fixed_stack_segment] #[inline(never)]
40+
pub fn new() -> StdIn {
41+
let fd = unsafe { libc::dup(libc::STDIN_FILENO) };
42+
StdIn { fd: file::FileDesc::new(fd) }
43+
}
44+
}
45+
46+
impl Reader for StdIn {
47+
fn read(&mut self, buf: &mut [u8]) -> Option<uint> { self.fd.read(buf) }
48+
fn eof(&mut self) -> bool { self.fd.eof() }
49+
}
50+
51+
pub struct StdOut {
52+
priv fd: file::FileDesc
53+
}
54+
55+
impl StdOut {
56+
/// Duplicates the specified file descriptor, returning an io::Writer
57+
#[fixed_stack_segment] #[inline(never)]
58+
pub fn new(fd: file::fd_t) -> StdOut {
59+
let fd = unsafe { libc::dup(fd) };
60+
StdOut { fd: file::FileDesc::new(fd) }
61+
}
62+
}
63+
64+
impl Writer for StdOut {
65+
fn write(&mut self, buf: &[u8]) { self.fd.write(buf) }
66+
fn flush(&mut self) { self.fd.flush() }
67+
}

0 commit comments

Comments
 (0)