diff --git a/Cargo.lock b/Cargo.lock index 508f03ab0..cfa6d4e7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3010,7 +3010,7 @@ dependencies = [ "filetime", "time", "uucore", - "winapi", + "windows-sys 0.42.0", ] [[package]] diff --git a/src/uu/touch/Cargo.toml b/src/uu/touch/Cargo.toml index 2e3504cbe..a8fadffdb 100644 --- a/src/uu/touch/Cargo.toml +++ b/src/uu/touch/Cargo.toml @@ -21,7 +21,7 @@ time = { version = "0.3", features = ["parsing", "formatting", "local-offset", " uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["libc"] } [target.'cfg(target_os = "windows")'.dependencies] -winapi = { version = "0.3" } +windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_Storage_FileSystem", "Win32_Foundation"] } [[bin]] name = "touch" diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index e94426aff..f397d2eaf 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -472,19 +472,16 @@ fn pathbuf_from_stdout() -> UResult { #[cfg(windows)] { use std::os::windows::prelude::AsRawHandle; - use winapi::shared::minwindef::{DWORD, MAX_PATH}; - use winapi::shared::winerror::{ - ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY, ERROR_PATH_NOT_FOUND, + use windows_sys::Win32::Foundation::{ + GetLastError, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY, ERROR_PATH_NOT_FOUND, + HANDLE, MAX_PATH, + }; + use windows_sys::Win32::Storage::FileSystem::{ + GetFinalPathNameByHandleW, FILE_NAME_OPENED, }; - use winapi::um::errhandlingapi::GetLastError; - use winapi::um::fileapi::GetFinalPathNameByHandleW; - use winapi::um::winnt::WCHAR; - let handle = std::io::stdout().lock().as_raw_handle(); - let mut file_path_buffer: [WCHAR; MAX_PATH as usize] = [0; MAX_PATH as usize]; - - // Couldn't find this in winapi - const FILE_NAME_OPENED: DWORD = 0x8; + let handle = std::io::stdout().lock().as_raw_handle() as HANDLE; + let mut file_path_buffer: [u16; MAX_PATH as usize] = [0; MAX_PATH as usize]; // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea#examples // SAFETY: We transmute the handle to be able to cast *mut c_void into a