Skip to content

Commit cdf0f73

Browse files
committed
Ignore mismatched lengths when writing to console on non-Unicode Windows.
Fixes #13 (more of a workaround)
1 parent 73168bc commit cdf0f73

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/std/src/sys/windows/stdio.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::os::windows::io::{FromRawHandle, IntoRawHandle};
77
use crate::ptr;
88
use crate::str;
99
use crate::sys::c;
10+
use crate::sys::compat;
1011
use crate::sys::cvt;
1112
use crate::sys::handle::Handle;
1213
use crate::sys::windows::api;
@@ -201,6 +202,11 @@ fn write_valid_utf8_to_console(handle: c::HANDLE, utf8: &str) -> io::Result<usiz
201202
if written == utf16.len() {
202203
Ok(utf8.len())
203204
} else {
205+
if !compat::is_windows_nt() {
206+
// FIXME: This function should manually convert to the target codepage on 9x/ME, and
207+
// handle incomplete writes by calculating how many utf8-effective bytes were written.
208+
return Ok(utf8.len());
209+
}
204210
// Make sure we didn't end up writing only half of a surrogate pair (even though the chance
205211
// is tiny). Because it is not possible for user code to re-slice `data` in such a way that
206212
// a missing surrogate can be produced (and also because of the UTF-8 validation above),

0 commit comments

Comments
 (0)