From 5ef1745960d47b3fce1c0d34d5fc041f2fcd2257 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Wed, 19 Oct 2022 23:40:00 +0300 Subject: [PATCH] tail: migrate `winapi` to `windows-sys` crate --- Cargo.lock | 2 +- src/uu/tail/Cargo.toml | 2 +- src/uu/tail/src/platform/windows.rs | 21 ++++++++------------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e17f84fd3..8972b01b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2968,8 +2968,8 @@ dependencies = [ "notify", "same-file", "uucore", - "winapi", "winapi-util", + "windows-sys 0.42.0", ] [[package]] diff --git a/src/uu/tail/Cargo.toml b/src/uu/tail/Cargo.toml index e417a49a5..a912bf352 100644 --- a/src/uu/tail/Cargo.toml +++ b/src/uu/tail/Cargo.toml @@ -24,7 +24,7 @@ uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=[ same-file = "1.0.6" [target.'cfg(windows)'.dependencies] -winapi = { version="0.3", features=["fileapi", "handleapi", "processthreadsapi", "synchapi", "winbase"] } +windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_System_Threading", "Win32_Foundation"] } winapi-util = { version="0.1.5" } [target.'cfg(unix)'.dependencies] diff --git a/src/uu/tail/src/platform/windows.rs b/src/uu/tail/src/platform/windows.rs index b5c139bbd..3e4cc7edc 100644 --- a/src/uu/tail/src/platform/windows.rs +++ b/src/uu/tail/src/platform/windows.rs @@ -6,17 +6,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ +use windows_sys::Win32::Foundation::{CloseHandle, BOOL, HANDLE, WAIT_FAILED, WAIT_OBJECT_0}; +use windows_sys::Win32::System::Threading::{ + OpenProcess, WaitForSingleObject, PROCESS_SYNCHRONIZE, +}; -extern crate winapi; - -use self::winapi::shared::minwindef::DWORD; -use self::winapi::um::handleapi::CloseHandle; -use self::winapi::um::processthreadsapi::OpenProcess; -use self::winapi::um::synchapi::WaitForSingleObject; -use self::winapi::um::winbase::{WAIT_FAILED, WAIT_OBJECT_0}; -use self::winapi::um::winnt::{HANDLE, SYNCHRONIZE}; - -pub type Pid = DWORD; +pub type Pid = u32; pub struct ProcessChecker { dead: bool, @@ -26,10 +21,10 @@ pub struct ProcessChecker { impl ProcessChecker { pub fn new(process_id: self::Pid) -> Self { #[allow(non_snake_case)] - let FALSE = 0i32; - let h = unsafe { OpenProcess(SYNCHRONIZE, FALSE, process_id as DWORD) }; + let FALSE: BOOL = 0; + let h = unsafe { OpenProcess(PROCESS_SYNCHRONIZE, FALSE, process_id) }; Self { - dead: h.is_null(), + dead: h == 0, handle: h, } }