diff options
| author | bors <bors@rust-lang.org> | 2025-02-24 10:27:53 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-02-24 10:27:53 +0000 | 
| commit | bb029a1d3f819471722f32dd9fcfa2c83d4f24f4 (patch) | |
| tree | fd4e4c3896ac33d634b549c77d2ad062cccea875 /library/std/src | |
| parent | f43e549b88698568581a9d329c7582e3708ac187 (diff) | |
| parent | 42014b44b3d91e6567bb666f02c37ba537af00d0 (diff) | |
| download | rust-bb029a1d3f819471722f32dd9fcfa2c83d4f24f4.tar.gz rust-bb029a1d3f819471722f32dd9fcfa2c83d4f24f4.zip | |
Auto merge of #137511 - jhpratt:rollup-07whsax, r=jhpratt
Rollup of 10 pull requests
Successful merges:
 - #136610 (Allow `IndexSlice` to be indexed by ranges.)
 - #136991 ([rustdoc] Add new setting to wrap source code lines when too long)
 - #137061 (Unstable `gen_future` Feature Tracking  )
 - #137393 (Stabilize `unbounded_shifts`)
 - #137482 (Windows: use existing wrappers in `File::open_native`)
 - #137484 (Fix documentation for unstable sort on slice)
 - #137491 (Tighten `str-to-string-128690.rs``CHECK{,-NOT}`s to make it less likely to incorrectly fail with symbol name mangling)
 - #137495 (Added into_value function to ControlFlow<T, T>)
 - #137501 (Move `impl` blocks out of `rustc_middle/src/mir/syntax.rs`)
 - #137505 (Add a span to `CompilerBuiltinsCannotCall`)
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sys/pal/windows/fs.rs | 36 | 
1 files changed, 11 insertions, 25 deletions
| diff --git a/library/std/src/sys/pal/windows/fs.rs b/library/std/src/sys/pal/windows/fs.rs index 0ddce30cf8e..dce5a429cb0 100644 --- a/library/std/src/sys/pal/windows/fs.rs +++ b/library/std/src/sys/pal/windows/fs.rs @@ -1,4 +1,4 @@ -use super::api::{self, WinError}; +use super::api::{self, WinError, set_file_information_by_handle}; use super::{IoResult, to_u16s}; use crate::alloc::{alloc, handle_alloc_error}; use crate::borrow::Cow; @@ -319,31 +319,17 @@ impl File { && creation == c::OPEN_ALWAYS && api::get_last_error() == WinError::ALREADY_EXISTS { - unsafe { - // This first tries `FileAllocationInfo` but falls back to - // `FileEndOfFileInfo` in order to support WINE. - // If WINE gains support for FileAllocationInfo, we should - // remove the fallback. - let alloc = c::FILE_ALLOCATION_INFO { AllocationSize: 0 }; - let result = c::SetFileInformationByHandle( - handle.as_raw_handle(), - c::FileAllocationInfo, - (&raw const alloc).cast::<c_void>(), - mem::size_of::<c::FILE_ALLOCATION_INFO>() as u32, - ); - if result == 0 { + // This first tries `FileAllocationInfo` but falls back to + // `FileEndOfFileInfo` in order to support WINE. + // If WINE gains support for FileAllocationInfo, we should + // remove the fallback. + let alloc = c::FILE_ALLOCATION_INFO { AllocationSize: 0 }; + set_file_information_by_handle(handle.as_raw_handle(), &alloc) + .or_else(|_| { let eof = c::FILE_END_OF_FILE_INFO { EndOfFile: 0 }; - let result = c::SetFileInformationByHandle( - handle.as_raw_handle(), - c::FileEndOfFileInfo, - (&raw const 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()); - } - } - } + set_file_information_by_handle(handle.as_raw_handle(), &eof) + }) + .io_result()?; } Ok(File { handle: Handle::from_inner(handle) }) } else { | 
