@@ -10,21 +10,27 @@ Copyright (C) 2024, Haenn Quentin.
10
10
#include <stdio.h>
11
11
#include <stdlib.h>
12
12
#include <string.h>
13
- #include <signal.h>
14
13
#include <time.h>
14
+ #include <assert.h>
15
+ #include <math.h>
16
+
15
17
#ifdef _WIN32
16
- #include <windows.h>
18
+ #include <windows.h>
19
+ #include <process.h>
20
+ #include <direct.h>
21
+ #define SIGINT 2
22
+ typedef void (* SignalHandlerFn )(int );
17
23
#elif defined(__APPLE__ ) || defined(__linux__ )
18
- #include <sys/time.h>
19
- #include <sys/resource.h>
20
- #include <sys/types.h>
24
+ #include <sys/time.h>
25
+ #include <sys/resource.h>
26
+ #include <sys/types.h>
27
+ #include <unistd.h>
28
+ #include <signal.h>
21
29
#else
22
- #error "Unsupported platform"
30
+ #error "Unsupported platform"
23
31
#endif
24
- #include <limits.h>
25
- #include <unistd.h>
26
- #include <math.h>
27
- #include <assert.h>
32
+
33
+
28
34
#include "mds3-util.h"
29
35
#include "util_heap.h"
30
36
@@ -1590,6 +1596,24 @@ void cleanup(){
1590
1596
}
1591
1597
}
1592
1598
1599
+ #ifdef _WIN32
1600
+ static BOOL WINAPI win32_handler (DWORD signal ) {
1601
+ if (signal == CTRL_C_EVENT ) {
1602
+ handler (SIGINT );
1603
+ return TRUE;
1604
+ }
1605
+ return FALSE;
1606
+ }
1607
+
1608
+ static void setup_signal_handler (SignalHandlerFn handler_fn ) {
1609
+ SetConsoleCtrlHandler (win32_handler , TRUE);
1610
+ }
1611
+ #else
1612
+ static void setup_signal_handler (void (* handler_fn )(int )) {
1613
+ signal (SIGINT , handler_fn );
1614
+ }
1615
+ #endif
1616
+
1593
1617
void handler (int sig ) {
1594
1618
cleanup ();
1595
1619
exit (sig );
@@ -1598,7 +1622,7 @@ void handler(int sig) {
1598
1622
struct Result * emos_main (int * edges , int n , int nb_edge ) {
1599
1623
1600
1624
// Set the signal handler
1601
- signal (SIGINT , handler );
1625
+ setup_signal_handler (SIGINT , handler );
1602
1626
1603
1627
_read_graph_from_edge_list (edges , n , nb_edge );
1604
1628
NB_NODE_O = NB_NODE ;
0 commit comments