Skip to content

Commit

Permalink
Fix Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed Dec 26, 2024
1 parent 8ec36b6 commit cc5df7f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl FilePath for File {

#[cfg(windows)]
fn path(&self) -> std::io::Result<PathBuf> {
use std::ffi::OsString;
use std::os::windows::{ffi::OsStringExt, io::AsRawHandle};
use windows::Win32::{
Foundation,
Expand All @@ -82,7 +83,7 @@ impl FilePath for File {
return Err(io::Error::last_os_error());
}

let mut path = Vec::with_capacity(len as usize);
let mut path = vec![0; len as usize];
let len2 = unsafe {
let handle = Foundation::HANDLE(self.as_raw_handle());
GetFinalPathNameByHandleW(handle, &mut path, GETFINALPATHNAMEBYHANDLE_FLAGS(0))
Expand All @@ -91,7 +92,7 @@ impl FilePath for File {
if len2 == 0 || len2 >= len {
return Err(io::Error::last_os_error());
}
unsafe { path.set_len(len2 as usize) };
path.truncate(len2 as usize);

// Turn the \\?\UNC\ network path prefix into \\.
let prefix = [
Expand Down

0 comments on commit cc5df7f

Please sign in to comment.