From 1f137c245fb848a4758ead2f5dbf56d475a90671 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 28 Dec 2019 11:46:27 -0600 Subject: [PATCH] refactor/polish ~ fix `cargo clippy` complaints (fatal/cast_ptr_alignment) --- src/cp/cp.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index 6b08a8e24..6013278a4 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -34,13 +34,18 @@ use kernel32::CreateFileW; extern crate winapi; use std::mem; +#[cfg(not(windows))] use std::ffi::CString; +#[cfg(windows)] +use std::ffi::OsStr; use clap::{App, Arg, ArgMatches}; use quick_error::ResultExt; use std::collections::HashSet; use std::fs; use std::io::{stdin, stdout, Write}; use std::io; +#[cfg(windows)] +use std::os::windows::ffi::OsStrExt; use std::path::{Path, PathBuf, StripPrefixError}; use std::str::FromStr; use uucore::fs::{canonicalize, CanonicalizeMode}; @@ -712,11 +717,11 @@ fn preserve_hardlinks( { if !source.is_dir() { unsafe { - let src_path = CString::new(source.as_os_str().to_str().unwrap()).unwrap(); let inode: u64; let nlinks: u64; #[cfg(unix)] { + let src_path = CString::new(source.as_os_str().to_str().unwrap()).unwrap(); let mut stat = mem::zeroed(); if libc::lstat(src_path.as_ptr(), &mut stat) < 0 { return Err(format!( @@ -730,9 +735,10 @@ fn preserve_hardlinks( } #[cfg(windows)] { + let src_path: Vec = OsStr::new(source).encode_wide().collect(); let stat = mem::uninitialized(); let handle = CreateFileW( - src_path.as_ptr() as *const u16, + src_path.as_ptr(), winapi::um::winnt::GENERIC_READ, winapi::um::winnt::FILE_SHARE_READ, std::ptr::null_mut(),