1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 13:07:46 +00:00

touch: migrate winapi to windows-sys crate

This commit is contained in:
Niyaz Nigmatullin 2022-10-20 00:00:08 +03:00 committed by Niyaz Nigmatullin
parent 580bff02f8
commit f95a14537b
3 changed files with 10 additions and 13 deletions

2
Cargo.lock generated
View file

@ -3010,7 +3010,7 @@ dependencies = [
"filetime",
"time",
"uucore",
"winapi",
"windows-sys 0.42.0",
]
[[package]]

View file

@ -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"

View file

@ -472,19 +472,16 @@ fn pathbuf_from_stdout() -> UResult<PathBuf> {
#[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