Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do with "SIGQUIT" signal when porting to mingw?

Tags:

c

mingw

porting

I'm trying to port some C software to win32 but I don't know how to handle the SIGQUIT signal. I checked the signal.h of Mingw and it doesn't support SIGQUIT (or SIGHUP for that matter, but I'm assuming I can just ignore that one).

It comes up multiple times, here is one example:

switch (sig) {
     case SIGHUP:
     case SIGINT:
     case SIGTERM:
     case SIGQUIT: {
         /*
         // Bunch of code here removed
         */
         exit(0);
         break;
     }
}

Any suggestions?

like image 914
Nate Avatar asked Aug 16 '13 19:08

Nate


1 Answers

Windows does only support a small range of signals. SIGQUIT is not supported. mingw just took the definitions from Microsoft.

I'd just check if it was defined before using it:

switch (sig) {
     case SIGINT:
     case SIGTERM:
#ifdef SIGHUP
     case SIGHUP:
#endif
#ifdef SIGQUIT
     case SIGQUIT:
#endif
     {
         /* ... */
     }
}

Or course, you could also check for _WIN32, which is always defined in common windows preprocessors, or __MINGW32__, which is always defined when using a mingw preprocessor. Don't get confused by the "32" in those names: Both will also be defined when compiling for 64-bit Windows.

like image 63
nmaier Avatar answered Oct 06 '22 01:10

nmaier