Skip to content

Commit cc5df7f

Browse files
committed
Fix Windows build
1 parent 8ec36b6 commit cc5df7f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl FilePath for File {
6767

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

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

9697
// Turn the \\?\UNC\ network path prefix into \\.
9798
let prefix = [

0 commit comments

Comments
 (0)