Skip to content

Commit 1b1b864

Browse files
authored
Rollup merge of rust-lang#59512 - euclio:stdio-locks, r=sfackler
implement `AsRawFd` for stdio locks cc rust-lang/rfcs#2074.
2 parents 3de2821 + e995fa8 commit 1b1b864

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ impl AsRawFd for io::Stderr {
115115
fn as_raw_fd(&self) -> RawFd { 2 }
116116
}
117117

118+
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
119+
impl<'a> AsRawFd for io::StdinLock<'a> {
120+
fn as_raw_fd(&self) -> RawFd { 0 }
121+
}
122+
123+
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
124+
impl<'a> AsRawFd for io::StdoutLock<'a> {
125+
fn as_raw_fd(&self) -> RawFd { 1 }
126+
}
127+
128+
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
129+
impl<'a> AsRawFd for io::StderrLock<'a> {
130+
fn as_raw_fd(&self) -> RawFd { 2 }
131+
}
132+
118133
#[stable(feature = "from_raw_os", since = "1.1.0")]
119134
impl FromRawFd for net::TcpStream {
120135
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {

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

+15
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,18 @@ impl AsRawFd for io::Stdout {
9595
impl AsRawFd for io::Stderr {
9696
fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO }
9797
}
98+
99+
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
100+
impl<'a> AsRawFd for io::StdinLock<'a> {
101+
fn as_raw_fd(&self) -> RawFd { libc::STDIN_FILENO }
102+
}
103+
104+
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
105+
impl<'a> AsRawFd for io::StdoutLock<'a> {
106+
fn as_raw_fd(&self) -> RawFd { libc::STDOUT_FILENO }
107+
}
108+
109+
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
110+
impl<'a> AsRawFd for io::StderrLock<'a> {
111+
fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO }
112+
}

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

+21
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,27 @@ impl AsRawHandle for io::Stderr {
8383
}
8484
}
8585

86+
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
87+
impl<'a> AsRawHandle for io::StdinLock<'a> {
88+
fn as_raw_handle(&self) -> RawHandle {
89+
unsafe { c::GetStdHandle(c::STD_INPUT_HANDLE) as RawHandle }
90+
}
91+
}
92+
93+
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
94+
impl<'a> AsRawHandle for io::StdoutLock<'a> {
95+
fn as_raw_handle(&self) -> RawHandle {
96+
unsafe { c::GetStdHandle(c::STD_OUTPUT_HANDLE) as RawHandle }
97+
}
98+
}
99+
100+
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
101+
impl<'a> AsRawHandle for io::StderrLock<'a> {
102+
fn as_raw_handle(&self) -> RawHandle {
103+
unsafe { c::GetStdHandle(c::STD_ERROR_HANDLE) as RawHandle }
104+
}
105+
}
106+
86107
#[stable(feature = "from_raw_os", since = "1.1.0")]
87108
impl FromRawHandle for fs::File {
88109
unsafe fn from_raw_handle(handle: RawHandle) -> fs::File {

0 commit comments

Comments
 (0)