Skip to content

Commit a671258

Browse files
committed
winapi -> windows-sys
1 parent f29f001 commit a671258

File tree

3 files changed

+81
-15
lines changed

3 files changed

+81
-15
lines changed

Cargo.lock

Lines changed: 67 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ termcolor = "1.1.0"
6060
textwrap = { version = "0.16.0", default-features = false }
6161

6262
[target.'cfg(target_os = "windows")'.dependencies]
63-
winapi = { version = "0.3.9", features = ["handleapi"] }
63+
windows-sys = { version = "0.52", features = ["Win32_Foundation", "Win32_System_Console", "Win32_System_Threading"] }
6464

6565
[target.'cfg(not(target_os = "windows"))'.dependencies]
6666
libc = "0.2.151"

crates/core/ctrlc.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,16 @@ mod ctrlc {
262262
mod windows {
263263
use super::*;
264264

265-
use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE};
266-
use winapi::um::consoleapi::{SetConsoleCtrlHandler, WriteConsoleA};
267-
use winapi::um::handleapi::DuplicateHandle;
268-
use winapi::um::processenv::GetStdHandle;
269-
use winapi::um::processthreadsapi::{
265+
use windows_sys::Win32::Foundation::{
266+
DuplicateHandle, BOOL, DUPLICATE_SAME_ACCESS, FALSE, HANDLE, TRUE,
267+
};
268+
use windows_sys::Win32::System::Console::{
269+
GetStdHandle, SetConsoleCtrlHandler, WriteConsoleA, CTRL_C_EVENT,
270+
STD_OUTPUT_HANDLE,
271+
};
272+
use windows_sys::Win32::System::Threading::{
270273
GetCurrentProcess, GetCurrentThread, SuspendThread,
271274
};
272-
use winapi::um::winbase::STD_OUTPUT_HANDLE;
273-
use winapi::um::wincon::CTRL_C_EVENT;
274-
use winapi::um::winnt::{DUPLICATE_SAME_ACCESS, HANDLE};
275275

276276
pub type ThreadType = HANDLE;
277277

@@ -280,7 +280,7 @@ mod ctrlc {
280280
const ANSI_RESET: &str = "\u{1B}[00m^C";
281281

282282
pub(super) fn thread_self() -> ThreadId {
283-
let mut this_thread: ThreadType = std::ptr::null_mut();
283+
let mut this_thread: ThreadType = 0;
284284

285285
// SAFETY: GetCurrentThread/Process can not fail. The thread handle on a failed
286286
// DuplicateHandle() call is not used.
@@ -303,7 +303,7 @@ mod ctrlc {
303303
})
304304
}
305305

306-
extern "system" fn on_ctrlc(event_type: DWORD) -> BOOL {
306+
extern "system" fn on_ctrlc(event_type: u32) -> BOOL {
307307
if event_type == CTRL_C_EVENT {
308308
// Observed behavior: When in a Ctrl-C handler (i.e. this), resetting it so the
309309
// next ^C is not handled by it does not work, this handler has to run to
@@ -325,16 +325,16 @@ mod ctrlc {
325325
// SAFETY: Only a valid handle is used later.
326326
let stdout_handle = unsafe { GetStdHandle(STD_OUTPUT_HANDLE) };
327327

328-
if stdout_handle != std::ptr::null_mut() {
329-
let mut _bytes_written: DWORD = 0;
328+
if stdout_handle != 0 {
329+
let mut _bytes_written: u32 = 0;
330330

331331
// Short writes or other errors are ignored.
332332
// SAFETY: correctness of `lpBuffer` and `nNumberOfCharsToWrite` is ensured by Rust.
333333
let _ = unsafe {
334334
WriteConsoleA(
335335
stdout_handle,
336336
ANSI_RESET.as_ptr() as *const _,
337-
ANSI_RESET.len() as DWORD,
337+
ANSI_RESET.len() as u32,
338338
&mut _bytes_written,
339339
std::ptr::null_mut(),
340340
)

0 commit comments

Comments
 (0)