File tree 1 file changed +6
-6
lines changed
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 21
21
#include < signal.h>
22
22
#include < unistd.h>
23
23
#elif defined (_WIN32)
24
+ #define WIN32_LEAN_AND_MEAN
25
+ #include < windows.h>
24
26
#include < signal.h>
25
27
#endif
26
28
@@ -215,7 +217,10 @@ int main(int argc, char ** argv) {
215
217
sigint_action.sa_flags = 0 ;
216
218
sigaction (SIGINT, &sigint_action, NULL );
217
219
#elif defined (_WIN32)
218
- signal (SIGINT, sigint_handler);
220
+ auto console_ctrl_handler = [](DWORD ctrl_type) -> BOOL {
221
+ return (ctrl_type == CTRL_C_EVENT) ? (sigint_handler (SIGINT), true ) : false ;
222
+ };
223
+ SetConsoleCtrlHandler (static_cast <PHANDLER_ROUTINE>(console_ctrl_handler), true );
219
224
#endif
220
225
221
226
fprintf (stderr, " %s: interactive mode on.\n " , __func__);
@@ -397,11 +402,6 @@ int main(int argc, char ** argv) {
397
402
// potentially set color to indicate we are taking user input
398
403
set_console_color (con_st, CONSOLE_COLOR_USER_INPUT);
399
404
400
- #if defined (_WIN32)
401
- // Windows: must reactivate sigint handler after each signal
402
- signal (SIGINT, sigint_handler);
403
- #endif
404
-
405
405
if (params.instruct ) {
406
406
printf (" \n > " );
407
407
}
You can’t perform that action at this time.
0 commit comments