1
1
#![ unstable( issue = "0" , feature = "windows_stdio" ) ]
2
2
3
3
use crate :: char:: decode_utf16;
4
- use crate :: cmp;
5
4
use crate :: io;
6
- use crate :: ptr ;
7
- use crate :: str;
5
+ # [ cfg ( not ( target_os = "uwp" ) ) ]
6
+ use crate :: { ptr , cmp , str} ;
8
7
use crate :: sys:: c;
8
+ #[ cfg( not( target_os = "uwp" ) ) ]
9
9
use crate :: sys:: cvt;
10
10
use crate :: sys:: handle:: Handle ;
11
11
12
12
// Don't cache handles but get them fresh for every read/write. This allows us to track changes to
13
13
// the value over time (such as if a process calls `SetStdHandle` while it's running). See #40490.
14
14
pub struct Stdin {
15
+ #[ allow( dead_code) ]
15
16
surrogate : u16 ,
16
17
}
17
18
pub struct Stdout ;
@@ -42,6 +43,7 @@ pub fn get_handle(handle_id: c::DWORD) -> io::Result<c::HANDLE> {
42
43
}
43
44
}
44
45
46
+ #[ cfg( not( target_os = "uwp" ) ) ]
45
47
fn is_console ( handle : c:: HANDLE ) -> bool {
46
48
// `GetConsoleMode` will return false (0) if this is a pipe (we don't care about the reported
47
49
// 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 {
50
52
unsafe { c:: GetConsoleMode ( handle, & mut mode) != 0 }
51
53
}
52
54
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" ) ) ]
53
65
fn write ( handle_id : c:: DWORD , data : & [ u8 ] ) -> io:: Result < usize > {
54
66
let handle = get_handle ( handle_id) ?;
55
67
if !is_console ( handle) {
@@ -113,6 +125,7 @@ fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
113
125
}
114
126
}
115
127
128
+ #[ cfg( not( target_os = "uwp" ) ) ]
116
129
fn write_u16s ( handle : c:: HANDLE , data : & [ u16 ] ) -> io:: Result < usize > {
117
130
let mut written = 0 ;
118
131
cvt ( unsafe {
@@ -132,6 +145,7 @@ impl Stdin {
132
145
}
133
146
134
147
impl io:: Read for Stdin {
148
+ #[ cfg( not( target_os = "uwp" ) ) ]
135
149
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
136
150
let handle = get_handle ( c:: STD_INPUT_HANDLE ) ?;
137
151
if !is_console ( handle) {
@@ -158,12 +172,22 @@ impl io::Read for Stdin {
158
172
159
173
utf16_to_utf8 ( & utf16_buf[ ..read] , buf)
160
174
}
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
+ }
161
184
}
162
185
163
186
164
187
// We assume that if the last `u16` is an unpaired surrogate they got sliced apart by our
165
188
// buffer size, and keep it around for the next read hoping to put them together.
166
189
// This is a best effort, and may not work if we are not the only reader on Stdin.
190
+ #[ cfg( not( target_os = "uwp" ) ) ]
167
191
fn read_u16s_fixup_surrogates ( handle : c:: HANDLE ,
168
192
buf : & mut [ u16 ] ,
169
193
mut amount : usize ,
@@ -194,6 +218,7 @@ fn read_u16s_fixup_surrogates(handle: c::HANDLE,
194
218
Ok ( amount)
195
219
}
196
220
221
+ #[ cfg( not( target_os = "uwp" ) ) ]
197
222
fn read_u16s ( handle : c:: HANDLE , buf : & mut [ u16 ] ) -> io:: Result < usize > {
198
223
// Configure the `pInputControl` parameter to not only return on `\r\n` but also Ctrl-Z, the
199
224
// traditional DOS method to indicate end of character stream / user input (SUB).
0 commit comments