11#![ unstable( issue = "0" , feature = "windows_stdio" ) ]
22
33use crate :: char:: decode_utf16;
4- use crate :: cmp;
54use crate :: io;
6- use crate :: ptr ;
7- use crate :: str;
5+ # [ cfg ( not ( target_os = "uwp" ) ) ]
6+ use crate :: { ptr , cmp , str} ;
87use crate :: sys:: c;
8+ #[ cfg( not( target_os = "uwp" ) ) ]
99use crate :: sys:: cvt;
1010use crate :: sys:: handle:: Handle ;
1111
1212// Don't cache handles but get them fresh for every read/write. This allows us to track changes to
1313// the value over time (such as if a process calls `SetStdHandle` while it's running). See #40490.
1414pub struct Stdin {
15+ #[ allow( dead_code) ]
1516 surrogate : u16 ,
1617}
1718pub struct Stdout ;
@@ -42,6 +43,7 @@ pub fn get_handle(handle_id: c::DWORD) -> io::Result<c::HANDLE> {
4243 }
4344}
4445
46+ #[ cfg( not( target_os = "uwp" ) ) ]
4547fn is_console ( handle : c:: HANDLE ) -> bool {
4648 // `GetConsoleMode` will return false (0) if this is a pipe (we don't care about the reported
4749 // mode). This will only detect Windows Console, not other terminals connected to a pipe like
@@ -50,6 +52,16 @@ fn is_console(handle: c::HANDLE) -> bool {
5052 unsafe { c:: GetConsoleMode ( handle, & mut mode) != 0 }
5153}
5254
55+ #[ cfg( target_os = "uwp" ) ]
56+ fn write ( handle_id : c:: DWORD , data : & [ u8 ] ) -> io:: Result < usize > {
57+ let handle = get_handle ( handle_id) ?;
58+ let handle = Handle :: new ( handle) ;
59+ let ret = handle. write ( data) ;
60+ handle. into_raw ( ) ; // Don't close the handle
61+ return ret;
62+ }
63+
64+ #[ cfg( not( target_os = "uwp" ) ) ]
5365fn write ( handle_id : c:: DWORD , data : & [ u8 ] ) -> io:: Result < usize > {
5466 let handle = get_handle ( handle_id) ?;
5567 if !is_console ( handle) {
@@ -113,6 +125,7 @@ fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
113125 }
114126}
115127
128+ #[ cfg( not( target_os = "uwp" ) ) ]
116129fn write_u16s ( handle : c:: HANDLE , data : & [ u16 ] ) -> io:: Result < usize > {
117130 let mut written = 0 ;
118131 cvt ( unsafe {
@@ -132,6 +145,7 @@ impl Stdin {
132145}
133146
134147impl io:: Read for Stdin {
148+ #[ cfg( not( target_os = "uwp" ) ) ]
135149 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
136150 let handle = get_handle ( c:: STD_INPUT_HANDLE ) ?;
137151 if !is_console ( handle) {
@@ -158,12 +172,22 @@ impl io::Read for Stdin {
158172
159173 utf16_to_utf8 ( & utf16_buf[ ..read] , buf)
160174 }
175+
176+ #[ cfg( target_os = "uwp" ) ]
177+ fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
178+ let handle = get_handle ( c:: STD_INPUT_HANDLE ) ?;
179+ let handle = Handle :: new ( handle) ;
180+ let ret = handle. read ( buf) ;
181+ handle. into_raw ( ) ; // Don't close the handle
182+ ret
183+ }
161184}
162185
163186
164187// We assume that if the last `u16` is an unpaired surrogate they got sliced apart by our
165188// buffer size, and keep it around for the next read hoping to put them together.
166189// This is a best effort, and may not work if we are not the only reader on Stdin.
190+ #[ cfg( not( target_os = "uwp" ) ) ]
167191fn read_u16s_fixup_surrogates ( handle : c:: HANDLE ,
168192 buf : & mut [ u16 ] ,
169193 mut amount : usize ,
@@ -194,6 +218,7 @@ fn read_u16s_fixup_surrogates(handle: c::HANDLE,
194218 Ok ( amount)
195219}
196220
221+ #[ cfg( not( target_os = "uwp" ) ) ]
197222fn read_u16s ( handle : c:: HANDLE , buf : & mut [ u16 ] ) -> io:: Result < usize > {
198223 // Configure the `pInputControl` parameter to not only return on `\r\n` but also Ctrl-Z, the
199224 // traditional DOS method to indicate end of character stream / user input (SUB).
0 commit comments