about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2023-12-17 17:54:20 +0000
committerChris Denton <chris@chrisdenton.dev>2023-12-17 17:57:33 +0000
commite585b0ed58b8b5bd3dd3b549be7e7313bbd7ce25 (patch)
tree7404e61a51de65df186f046dd5ebef2d863c419f
parent3a2aa5854cbeb6fea24d6d0175d16c734aa9302e (diff)
downloadrust-e585b0ed58b8b5bd3dd3b549be7e7313bbd7ce25.tar.gz
rust-e585b0ed58b8b5bd3dd3b549be7e7313bbd7ce25.zip
Use FileEndOfFileInfo, not FileAllocationInfo
This fixes WINE support
-rw-r--r--library/std/src/sys/windows/fs.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs
index 09dfb0caeec..42484543686 100644
--- a/library/std/src/sys/windows/fs.rs
+++ b/library/std/src/sys/windows/fs.rs
@@ -309,14 +309,16 @@ impl File {
                 && unsafe { c::GetLastError() } == c::ERROR_ALREADY_EXISTS
             {
                 unsafe {
-                    // Setting the allocation size to zero also sets the
-                    // EOF position to zero.
-                    let alloc = c::FILE_ALLOCATION_INFO { AllocationSize: 0 };
+                    // This originally used `FileAllocationInfo` instead of
+                    // `FileEndOfFileInfo` but that wasn't supported by WINE.
+                    // It's arguable which fits the semantics of `OpenOptions`
+                    // better so let's just use the more widely supported method.
+                    let eof = c::FILE_END_OF_FILE_INFO { EndOfFile: 0 };
                     let result = c::SetFileInformationByHandle(
                         handle.as_raw_handle(),
-                        c::FileAllocationInfo,
-                        ptr::addr_of!(alloc).cast::<c_void>(),
-                        mem::size_of::<c::FILE_ALLOCATION_INFO>() as u32,
+                        c::FileEndOfFileInfo,
+                        ptr::addr_of!(eof).cast::<c_void>(),
+                        mem::size_of::<c::FILE_END_OF_FILE_INFO>() as u32,
                     );
                     if result == 0 {
                         return Err(io::Error::last_os_error());