Skip to content

Commit 7fef7d9

Browse files
committed
---
yaml --- r: 83820 b: refs/heads/try c: edf4c16 h: refs/heads/master v: v3
1 parent f75a3a6 commit 7fef7d9

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: b509f7905a578663d57121973b4a9a6b619341c2
5+
refs/heads/try: edf4c16997af6af08ef734ad34eccc5aa279595a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
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)