File tree 1 file changed +19
-9
lines changed
library/std/src/sys/windows
1 file changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -291,15 +291,25 @@ fn read_u16s(handle: c::HANDLE, buf: &mut [u16]) -> io::Result<usize> {
291
291
} ;
292
292
293
293
let mut amount = 0 ;
294
- cvt ( unsafe {
295
- c:: ReadConsoleW (
296
- handle,
297
- buf. as_mut_ptr ( ) as c:: LPVOID ,
298
- buf. len ( ) as u32 ,
299
- & mut amount,
300
- & mut input_control as c:: PCONSOLE_READCONSOLE_CONTROL ,
301
- )
302
- } ) ?;
294
+ loop {
295
+ cvt ( unsafe {
296
+ c:: SetLastError ( 0 ) ;
297
+ c:: ReadConsoleW (
298
+ handle,
299
+ buf. as_mut_ptr ( ) as c:: LPVOID ,
300
+ buf. len ( ) as u32 ,
301
+ & mut amount,
302
+ & mut input_control as c:: PCONSOLE_READCONSOLE_CONTROL ,
303
+ )
304
+ } ) ?;
305
+
306
+ // ReadConsoleW returns success with ERROR_OPERATION_ABORTED for Ctrl-C or Ctrl-Break.
307
+ // Explicitly check for that case here and try again.
308
+ if amount == 0 && unsafe { c:: GetLastError ( ) } == c:: ERROR_OPERATION_ABORTED {
309
+ continue ;
310
+ }
311
+ break ;
312
+ }
303
313
304
314
if amount > 0 && buf[ amount as usize - 1 ] == CTRL_Z {
305
315
amount -= 1 ;
You can’t perform that action at this time.
0 commit comments