From: Elias Fleckenstein Date: Sun, 24 Apr 2022 15:55:53 +0000 (+0200) Subject: Add win32 workaround for signal code X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=9678cac797ca82eaa1a70e6a6c4d570d6a7bce0d;p=dragonblocks_alpha.git Add win32 workaround for signal code --- diff --git a/src/interrupt.c b/src/interrupt.c index c11c3cd..2b9052c 100644 --- a/src/interrupt.c +++ b/src/interrupt.c @@ -4,7 +4,25 @@ #include "interrupt.h" Flag interrupt; -static struct sigaction sa = {0}; + +#ifdef _WIN32 + +// just the signals we need, for Win32 +static const char *strsignal(int sig) +{ + switch (sig) { + case SIGINT: + return "Interrupted"; + + case SIGTERM: + return "Terminated"; + + default: + return "Unknown signal"; + } +} + +#endif // _WIN32 static void interrupt_handler(int sig) { @@ -16,9 +34,15 @@ void interrupt_init() { flag_ini(&interrupt); +#ifdef _WIN32 + signal(SIGINT, interrupt_handler); + signal(SIGTERM, interrupt_handler); +#else // _WIN32 + struct sigaction sa = {0}; sa.sa_handler = &interrupt_handler; sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); +#endif // _WIN32 } void interrupt_deinit()