Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6d3db55

Browse files
committedDec 27, 2024
Auto merge of #134822 - jieyouxu:rollup-5xuaq82, r=jieyouxu
Rollup of 8 pull requests Successful merges: - #134606 (ptr::copy: fix docs for the overlapping case) - #134622 (Windows: Use WriteFile to write to a UTF-8 console) - #134759 (compiletest: Remove the `-test` suffix from normalize directives) - #134787 (Spruce up the docs of several queries related to the type/trait system and const eval) - #134806 (rustdoc: use shorter paths as preferred canonical paths) - #134815 (Sort triples by name in platform_support.md) - #134816 (tools: fix build failure caused by PR #134420) - #134819 (Fix mistake in windows file open) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 42591a4 + 5544091 commit 6d3db55

File tree

263 files changed

+897
-691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

263 files changed

+897
-691
lines changed
 

‎library/std/src/sys/pal/windows/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl File {
323323
let alloc = c::FILE_ALLOCATION_INFO { AllocationSize: 0 };
324324
let result = c::SetFileInformationByHandle(
325325
handle.as_raw_handle(),
326-
c::FileEndOfFileInfo,
326+
c::FileAllocationInfo,
327327
(&raw const alloc).cast::<c_void>(),
328328
mem::size_of::<c::FILE_ALLOCATION_INFO>() as u32,
329329
);

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,43 @@ fn is_console(handle: c::HANDLE) -> bool {
8484
unsafe { c::GetConsoleMode(handle, &mut mode) != 0 }
8585
}
8686

87+
/// Returns true if the attached console's code page is currently UTF-8.
88+
#[cfg(not(target_vendor = "win7"))]
89+
fn is_utf8_console() -> bool {
90+
unsafe { c::GetConsoleOutputCP() == c::CP_UTF8 }
91+
}
92+
93+
#[cfg(target_vendor = "win7")]
94+
fn is_utf8_console() -> bool {
95+
// Windows 7 has a fun "feature" where WriteFile on a console handle will return
96+
// the number of UTF-16 code units written and not the number of bytes from the input string.
97+
// So we always claim the console isn't UTF-8 to trigger the WriteConsole fallback code.
98+
false
99+
}
100+
87101
fn write(handle_id: u32, data: &[u8], incomplete_utf8: &mut IncompleteUtf8) -> io::Result<usize> {
88102
if data.is_empty() {
89103
return Ok(0);
90104
}
91105

92106
let handle = get_handle(handle_id)?;
93-
if !is_console(handle) {
107+
if !is_console(handle) || is_utf8_console() {
94108
unsafe {
95109
let handle = Handle::from_raw_handle(handle);
96110
let ret = handle.write(data);
97111
let _ = handle.into_raw_handle(); // Don't close the handle
98112
return ret;
99113
}
114+
} else {
115+
write_console_utf16(data, incomplete_utf8, handle)
100116
}
117+
}
101118

119+
fn write_console_utf16(
120+
data: &[u8],
121+
incomplete_utf8: &mut IncompleteUtf8,
122+
handle: c::HANDLE,
123+
) -> io::Result<usize> {
102124
if incomplete_utf8.len > 0 {
103125
assert!(
104126
incomplete_utf8.len < 4,
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.