Skip to content

Commit 85ef570

Browse files
committed
Implement AsRawFd for Stdin, Stdout, and Stderr
1 parent b80e946 commit 85ef570

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/libstd/sys/redox/ext/io.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use fs;
1616
use net;
1717
use sys;
18+
use io;
1819
use sys_common::{self, AsInner, FromInner, IntoInner};
1920

2021
/// Raw file descriptors.
@@ -109,6 +110,21 @@ impl AsRawFd for net::UdpSocket {
109110
}
110111
}
111112

113+
#[stable(feature = "rust1", since = "1.0.0")]
114+
impl AsRawFd for io::Stdin {
115+
fn as_raw_fd(&self) -> RawFd { 0 }
116+
}
117+
118+
#[stable(feature = "rust1", since = "1.0.0")]
119+
impl AsRawFd for io::Stdout {
120+
fn as_raw_fd(&self) -> RawFd { 1 }
121+
}
122+
123+
#[stable(feature = "rust1", since = "1.0.0")]
124+
impl AsRawFd for io::Stderr {
125+
fn as_raw_fd(&self) -> RawFd { 2 }
126+
}
127+
112128
#[stable(feature = "from_raw_os", since = "1.1.0")]
113129
impl FromRawFd for net::TcpStream {
114130
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {

src/libstd/sys/unix/ext/io.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use fs;
1616
use net;
1717
use os::raw;
1818
use sys;
19+
use io;
1920
use sys_common::{self, AsInner, FromInner, IntoInner};
21+
use libc;
2022

2123
/// Raw file descriptors.
2224
#[stable(feature = "rust1", since = "1.0.0")]
@@ -104,6 +106,21 @@ impl AsRawFd for net::UdpSocket {
104106
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
105107
}
106108

109+
#[stable(feature = "rust1", since = "1.0.0")]
110+
impl AsRawFd for io::Stdin {
111+
fn as_raw_fd(&self) -> RawFd { libc::STDIN_FILENO }
112+
}
113+
114+
#[stable(feature = "rust1", since = "1.0.0")]
115+
impl AsRawFd for io::Stdout {
116+
fn as_raw_fd(&self) -> RawFd { libc::STDOUT_FILENO }
117+
}
118+
119+
#[stable(feature = "rust1", since = "1.0.0")]
120+
impl AsRawFd for io::Stderr {
121+
fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO }
122+
}
123+
107124
#[stable(feature = "from_raw_os", since = "1.1.0")]
108125
impl FromRawFd for net::TcpStream {
109126
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {

0 commit comments

Comments
 (0)