File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1515use fs;
1616use net;
1717use sys;
18+ use io;
1819use 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 = "asraw_stdio" , since = "1.21.0" ) ]
114+ impl AsRawFd for io:: Stdin {
115+ fn as_raw_fd ( & self ) -> RawFd { 0 }
116+ }
117+
118+ #[ stable( feature = "asraw_stdio" , since = "1.21.0" ) ]
119+ impl AsRawFd for io:: Stdout {
120+ fn as_raw_fd ( & self ) -> RawFd { 1 }
121+ }
122+
123+ #[ stable( feature = "asraw_stdio" , since = "1.21.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" ) ]
113129impl FromRawFd for net:: TcpStream {
114130 unsafe fn from_raw_fd ( fd : RawFd ) -> net:: TcpStream {
Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ use fs;
1616use net;
1717use os:: raw;
1818use sys;
19+ use io;
1920use 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 = "asraw_stdio" , since = "1.21.0" ) ]
110+ impl AsRawFd for io:: Stdin {
111+ fn as_raw_fd ( & self ) -> RawFd { libc:: STDIN_FILENO }
112+ }
113+
114+ #[ stable( feature = "asraw_stdio" , since = "1.21.0" ) ]
115+ impl AsRawFd for io:: Stdout {
116+ fn as_raw_fd ( & self ) -> RawFd { libc:: STDOUT_FILENO }
117+ }
118+
119+ #[ stable( feature = "asraw_stdio" , since = "1.21.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" ) ]
108125impl FromRawFd for net:: TcpStream {
109126 unsafe fn from_raw_fd ( fd : RawFd ) -> net:: TcpStream {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use os::windows::raw;
1515use net;
1616use sys_common:: { self , AsInner , FromInner , IntoInner } ;
1717use sys;
18+ use io;
1819use sys:: c;
1920
2021/// Raw HANDLEs.
@@ -71,6 +72,27 @@ impl AsRawHandle for fs::File {
7172 }
7273}
7374
75+ #[ stable( feature = "asraw_stdio" , since = "1.21.0" ) ]
76+ impl AsRawHandle for io:: Stdin {
77+ fn as_raw_handle ( & self ) -> RawHandle {
78+ unsafe { c:: GetStdHandle ( c:: STD_INPUT_HANDLE ) as RawHandle }
79+ }
80+ }
81+
82+ #[ stable( feature = "asraw_stdio" , since = "1.21.0" ) ]
83+ impl AsRawHandle for io:: Stdout {
84+ fn as_raw_handle ( & self ) -> RawHandle {
85+ unsafe { c:: GetStdHandle ( c:: STD_OUTPUT_HANDLE ) as RawHandle }
86+ }
87+ }
88+
89+ #[ stable( feature = "asraw_stdio" , since = "1.21.0" ) ]
90+ impl AsRawHandle for io:: Stderr {
91+ fn as_raw_handle ( & self ) -> RawHandle {
92+ unsafe { c:: GetStdHandle ( c:: STD_ERROR_HANDLE ) as RawHandle }
93+ }
94+ }
95+
7496#[ stable( feature = "from_raw_os" , since = "1.1.0" ) ]
7597impl FromRawHandle for fs:: File {
7698 unsafe fn from_raw_handle ( handle : RawHandle ) -> fs:: File {
You can’t perform that action at this time.
0 commit comments