Function init_ctrlc

Source
pub fn init_ctrlc() -> Result<()>
Expand description

Initializes the SIGINT (Ctrl-C) signal handler.

This function installs a minimal, signal-safe handler for SIGINT. Once installed, any incoming Ctrl-C will set an internal flag, which can later be queried via is_ctrlc_received().

This function may be called multiple times; the signal handler will only be installed once. Repeated calls are safe and have no additional effect.

§Errors

Returns an Err if the underlying system call (sigaction) fails during handler installation. This typically indicates a low-level OS error or permission issue.

§Examples

ctrlc_tiny::init_ctrlc()?;
loop {
    if ctrlc_tiny::is_ctrlc_received() {
        println!("Ctrl-C detected!");
        break;
    }
}