ctrlc-tiny
A tiny crate for checking if Ctrl-C was pressed.
No handlers to set. No threads. No AtomicBool.
Just call init_ctrlc() once, then check is_ctrlc_received() in your loop.
✨ Features
- Signal-safe
SIGINThandler - No threads, no allocations
- Zero dependencies
- Ideal for polling-based CLI tools
🚀 Usage
Add to your Cargo.toml:
= "0.1"
Example:
🔍 Why not use ctrlc?
ctrlc provides a flexible way to handle signals using closures and shared state.
It spawns a thread and communicates through channels, which is great for many use cases but may be more than you need if you're just polling for Ctrl-C.
ctrlc-tiny is focused on one job: setting a flag when SIGINT is received.
No threads, no handlers, no extra logic.
🔒 Signal Safety
- Internally uses a
volatile sig_atomic_tflag — safe in POSIX signal handlers. - No heap, no threads — fully signal-safe by design.
🛠️ Platform Support
- ✅ Linux
- ✅ macOS
- ❌ Windows
📦 License
Licensed under either of:
- MIT
- Apache 2.0
See LICENSE-MIT or LICENSE-APACHE.