I am porting a Linux/gcc program under windows and implemented common exceptions handling for both. I was wondering what would be the equivalent of SIGINT
signal for MinGW/gcc.
Here is how I handle it under Linux :
static void handler(int sig)
{
// Catch exceptions
switch(sig)
{
case SIGABRT:
fputs("Caught SIGABRT: usually caused by an abort() or assert()
", stderr);
break;
case SIGFPE:
fputs("Caught SIGFPE: arithmetic exception, such as divide by zero
",
stderr);
break;
case SIGILL:
fputs("Caught SIGILL: illegal instruction
", stderr);
break;
case SIGINT:
fputs("Caught SIGINT: interactive attention signal, probably a ctrl+c
",
stderr);
break;
case SIGSEGV:
fputs("Caught SIGSEGV: segfault
", stderr);
break;
case SIGTERM:
default:
fputs("Caught SIGTERM: a termination request was sent to the program
",
stderr);
break;
}
// Ctrl+C interrupt => No backtrace
if (sig != (int)SIGINT)
{
fprintf(stderr, "Error: signal %d:
", sig);
posix_print_stack_trace();
}
exit(sig);
}
signal(SIGABRT, handler);
signal(SIGFPE, handler);
signal(SIGILL, handler);
signal(SIGINT, handler);
signal(SIGSEGV, handler);
signal(SIGTERM, handler);
Under Windows, this looks like :
static LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS * ExceptionInfo)
{
switch(ExceptionInfo->ExceptionRecord->ExceptionCode)
{
case EXCEPTION_ACCESS_VIOLATION:
fputs("Error: EXCEPTION_ACCESS_VIOLATION
", stderr);
break;
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
fputs("Error: EXCEPTION_ARRAY_BOUNDS_EXCEEDED
", stderr);
break;
case EXCEPTION_BREAKPOINT:
fputs("Error: EXCEPTION_BREAKPOINT
", stderr);
break;
...
}
}
if (EXCEPTION_STACK_OVERFLOW != ExceptionInfo->ExceptionRecord->ExceptionCode)
{
windows_print_stacktrace(ExceptionInfo->ContextRecord);
}
My problem is that I don't see any equivalent of SIGINT
in the EXCEPTION_*
available for Windows.
How would it be done catching a "CTRL+C" interruption under Windows (MinGW/gcc) ?
Thanks a lot.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…