diff options
| author | bors <bors@rust-lang.org> | 2021-10-14 16:23:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-10-14 16:23:10 +0000 |
| commit | e1e9319d93aea755c444c8f8ff863b0936d7a4b6 (patch) | |
| tree | 1b4c2feb07a917fc7d0340f992dfc42c27ed1536 /library/std/src/sys | |
| parent | 0a56eb11fafdd3c9d86c100b6b90505f5f9fdb00 (diff) | |
| parent | d6eff5ac4c3dcb3eb5c83a1a2a6ea8437450f25b (diff) | |
Auto merge of #89882 - matthiaskrgr:rollup-1dh7pz8, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #89390 (Fix incorrect Box::pin suggestion) - #89433 (Fix ctrl-c causing reads of stdin to return empty on Windows.) - #89823 (Switch order of terms to prevent overflow) - #89865 (Allow static linking LLVM with ThinLTO) - #89873 (Add missing word to `FromStr` trait documentation) - #89878 (Fix missing remaining compiler specific cfg information) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/windows/stdio.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/library/std/src/sys/windows/stdio.rs b/library/std/src/sys/windows/stdio.rs index 2719a530dfd..a4fe5f67f69 100644 --- a/library/std/src/sys/windows/stdio.rs +++ b/library/std/src/sys/windows/stdio.rs @@ -291,15 +291,25 @@ fn read_u16s(handle: c::HANDLE, buf: &mut [u16]) -> io::Result<usize> { }; let mut amount = 0; - cvt(unsafe { - c::ReadConsoleW( - handle, - buf.as_mut_ptr() as c::LPVOID, - buf.len() as u32, - &mut amount, - &mut input_control as c::PCONSOLE_READCONSOLE_CONTROL, - ) - })?; + loop { + cvt(unsafe { + c::SetLastError(0); + c::ReadConsoleW( + handle, + buf.as_mut_ptr() as c::LPVOID, + buf.len() as u32, + &mut amount, + &mut input_control as c::PCONSOLE_READCONSOLE_CONTROL, + ) + })?; + + // ReadConsoleW returns success with ERROR_OPERATION_ABORTED for Ctrl-C or Ctrl-Break. + // Explicitly check for that case here and try again. + if amount == 0 && unsafe { c::GetLastError() } == c::ERROR_OPERATION_ABORTED { + continue; + } + break; + } if amount > 0 && buf[amount as usize - 1] == CTRL_Z { amount -= 1; |
