mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 15:07:47 +00:00
refactor/polish ~ fix cargo clippy
complaints (fatal/cast_ptr_alignment)
This commit is contained in:
parent
c969becbf8
commit
1f137c245f
1 changed files with 8 additions and 2 deletions
10
src/cp/cp.rs
10
src/cp/cp.rs
|
@ -34,13 +34,18 @@ use kernel32::CreateFileW;
|
||||||
extern crate winapi;
|
extern crate winapi;
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
#[cfg(not(windows))]
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::ffi::OsStr;
|
||||||
use clap::{App, Arg, ArgMatches};
|
use clap::{App, Arg, ArgMatches};
|
||||||
use quick_error::ResultExt;
|
use quick_error::ResultExt;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{stdin, stdout, Write};
|
use std::io::{stdin, stdout, Write};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::os::windows::ffi::OsStrExt;
|
||||||
use std::path::{Path, PathBuf, StripPrefixError};
|
use std::path::{Path, PathBuf, StripPrefixError};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use uucore::fs::{canonicalize, CanonicalizeMode};
|
use uucore::fs::{canonicalize, CanonicalizeMode};
|
||||||
|
@ -712,11 +717,11 @@ fn preserve_hardlinks(
|
||||||
{
|
{
|
||||||
if !source.is_dir() {
|
if !source.is_dir() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let src_path = CString::new(source.as_os_str().to_str().unwrap()).unwrap();
|
|
||||||
let inode: u64;
|
let inode: u64;
|
||||||
let nlinks: u64;
|
let nlinks: u64;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
|
let src_path = CString::new(source.as_os_str().to_str().unwrap()).unwrap();
|
||||||
let mut stat = mem::zeroed();
|
let mut stat = mem::zeroed();
|
||||||
if libc::lstat(src_path.as_ptr(), &mut stat) < 0 {
|
if libc::lstat(src_path.as_ptr(), &mut stat) < 0 {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
|
@ -730,9 +735,10 @@ fn preserve_hardlinks(
|
||||||
}
|
}
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
|
let src_path: Vec<u16> = OsStr::new(source).encode_wide().collect();
|
||||||
let stat = mem::uninitialized();
|
let stat = mem::uninitialized();
|
||||||
let handle = CreateFileW(
|
let handle = CreateFileW(
|
||||||
src_path.as_ptr() as *const u16,
|
src_path.as_ptr(),
|
||||||
winapi::um::winnt::GENERIC_READ,
|
winapi::um::winnt::GENERIC_READ,
|
||||||
winapi::um::winnt::FILE_SHARE_READ,
|
winapi::um::winnt::FILE_SHARE_READ,
|
||||||
std::ptr::null_mut(),
|
std::ptr::null_mut(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue