- commit
- 397f01d4cedcadc0d151f9e34ea91d4711072eef
- parent
- 037fe394d682d653c092295ab274634d144f5e59
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-03-29 20:48
use sigaction() instead of signal() signal() is not portable
Diffstat
| M | src/main.rs | 18 | ++++++++++++++---- |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
@@ -49,15 +49,25 @@ fn render_health_bar(player: &game::Player, screen: &mut term::Screen) {
49 49 render_bar(screen, value, screen.height - 3, RED);
50 50 }
51 51
-1 52 fn signal(sig: libc::c_int, handler: libc::sighandler_t) {
-1 53 let mut action: libc::sigaction;
-1 54 unsafe {
-1 55 action = std::mem::zeroed();
-1 56 action.sa_sigaction = handler;
-1 57 libc::sigemptyset(&mut action.sa_mask);
-1 58 action.sa_flags = libc::SA_RESTART;
-1 59 action.sa_restorer = None;
-1 60 libc::sigaction(sig, &action, std::ptr::null_mut());
-1 61 }
-1 62 }
-1 63
52 64 fn main() {
53 65 let input = input::Input::new();
54 66 let mut screen = term::Screen::new();
55 67 let mut game = game::Game::new();
56 68
57 -1 unsafe {
58 -1 libc::signal(libc::SIGINT, quit as libc::sighandler_t);
59 -1 libc::signal(libc::SIGWINCH, resize as libc::sighandler_t);
60 -1 }
-1 69 signal(libc::SIGINT, quit as libc::sighandler_t);
-1 70 signal(libc::SIGWINCH, resize as libc::sighandler_t);
61 71
62 72 let mut time0 = time::Instant::now();
63 73