Skip to content

Commit 657c176

Browse files
committed
Fix weird build failure when cross-compiling from non-Windows hosts
Fix #16
1 parent 3fcf99d commit 657c176

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/internals.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ use std::{io, os::windows::io::AsRawHandle};
1414

1515
use winapi::um::winnt::{IO_REPARSE_TAG_MOUNT_POINT, MAXIMUM_REPARSE_DATA_BUFFER_SIZE};
1616

17+
const _: () = {
18+
use std::mem::{align_of, size_of};
19+
let std_size = size_of::<std::os::windows::io::RawHandle>();
20+
let winapi_size = size_of::<winapi::um::winnt::HANDLE>();
21+
let std_align = align_of::<std::os::windows::io::RawHandle>();
22+
let winapi_align = align_of::<winapi::um::winnt::HANDLE>();
23+
assert!(std_size == winapi_size);
24+
assert!(std_align == winapi_align);
25+
};
26+
1727
/// This prefix indicates to NTFS that the path is to be treated as a non-interpreted
1828
/// path in the virtual file system.
1929
const NON_INTERPRETED_PATH_PREFIX: [u16; 4] = [b'\\' as u16, b'?' as _, b'?' as _, b'\\' as _];
@@ -77,12 +87,12 @@ pub fn create(target: &Path, junction: &Path) -> io::Result<()> {
7787
size.wrapping_add(REPARSE_DATA_BUFFER_HEADER_SIZE)
7888
};
7989

80-
helpers::set_reparse_point(file.as_raw_handle(), rdb, u32::from(in_buffer_size))
90+
helpers::set_reparse_point(file.as_raw_handle().cast(), rdb, u32::from(in_buffer_size))
8191
}
8292

8393
pub fn delete(junction: &Path) -> io::Result<()> {
8494
let file = helpers::open_reparse_point(junction, true)?;
85-
helpers::delete_reparse_point(file.as_raw_handle())
95+
helpers::delete_reparse_point(file.as_raw_handle().cast())
8696
}
8797

8898
const _: () = {
@@ -108,7 +118,7 @@ pub fn exists(junction: &Path) -> io::Result<bool> {
108118
value: Vec::with_capacity(MAXIMUM_REPARSE_DATA_BUFFER_SIZE as usize),
109119
};
110120
let rdb = data.value.as_mut_ptr().cast::<ReparseDataBuffer>();
111-
helpers::get_reparse_data_point(file.as_raw_handle(), rdb)?;
121+
helpers::get_reparse_data_point(file.as_raw_handle().cast(), rdb)?;
112122
// The reparse tag indicates if this is a junction or not
113123
Ok(unsafe { (*rdb).reparse_tag } == IO_REPARSE_TAG_MOUNT_POINT)
114124
}
@@ -122,7 +132,7 @@ pub fn get_target(junction: &Path) -> io::Result<PathBuf> {
122132
value: Vec::with_capacity(MAXIMUM_REPARSE_DATA_BUFFER_SIZE as usize),
123133
};
124134
let rdb = data.value.as_mut_ptr().cast::<ReparseDataBuffer>();
125-
helpers::get_reparse_data_point(file.as_raw_handle(), rdb)?;
135+
helpers::get_reparse_data_point(file.as_raw_handle().cast(), rdb)?;
126136
let rdb = unsafe { &*rdb };
127137
if rdb.reparse_tag == IO_REPARSE_TAG_MOUNT_POINT {
128138
let offset = rdb.reparse_buffer.substitute_name_offset / WCHAR_SIZE;

0 commit comments

Comments
 (0)