Files
topgrade/src/ctrlc/windows.rs

22 lines
578 B
Rust
Raw Normal View History

2018-12-31 14:07:55 +02:00
//! A stub for Ctrl + C handling.
use crate::ctrlc::interrupted::set_interrupted;
use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE};
use winapi::um::consoleapi::SetConsoleCtrlHandler;
use winapi::um::wincon::CTRL_C_EVENT;
2018-12-31 14:07:55 +02:00
extern "system" fn handler(ctrl_type: DWORD) -> BOOL {
match ctrl_type {
CTRL_C_EVENT => {
set_interrupted();
TRUE
}
_ => FALSE,
}
}
pub fn set_handler() {
if 0 == unsafe { SetConsoleCtrlHandler(Some(handler), TRUE) } {
2022-11-16 13:43:57 -05:00
tracing::error!("Cannot set a control C handler")
}
}