]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Add win32 workaround for signal code
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 24 Apr 2022 15:55:53 +0000 (17:55 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 24 Apr 2022 15:55:53 +0000 (17:55 +0200)
src/interrupt.c

index c11c3cda4f151832cba17342725e3b123b24a9a7..2b9052c0b0b0310cda97b185049508c9dbbc564a 100644 (file)
@@ -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()