mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
feat: SignalHandler.cc add windows support
sigaction -> signal write -> fwrite
This commit is contained in:
parent
6f85c88b1d
commit
e09f0f47f3
@ -23,8 +23,13 @@ messages when FontForge can't save a file for us.
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <csignal>
|
||||||
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "pdf2htmlEX-config.h"
|
#include "pdf2htmlEX-config.h"
|
||||||
#include "util/ffw.h"
|
#include "util/ffw.h"
|
||||||
@ -95,11 +100,31 @@ const char* detailsBody = "no details recorded\n";
|
|||||||
const char* pdf2htmlEXTmpDir = NULL;
|
const char* pdf2htmlEXTmpDir = NULL;
|
||||||
const char* ffwAction = NULL;
|
const char* ffwAction = NULL;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
|
#endif
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunused-result"
|
#pragma GCC diagnostic ignored "-Wunused-result"
|
||||||
void signalHandler(int sigInt) {
|
void signalHandler(int sigInt) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
FILE *stderrFile = stderr;
|
||||||
|
fwrite(oopsMessage, strlen(oopsMessage), 1, stderrFile);
|
||||||
|
|
||||||
|
if (ffwAction) {
|
||||||
|
fwrite(ffwMessage_1, strlen(ffwMessage_1), 1, stderrFile);
|
||||||
|
fwrite(ffwAction, strlen(ffwAction), 1, stderrFile);
|
||||||
|
fwrite(ffwMessage_2, strlen(ffwMessage_2), 1, stderrFile);
|
||||||
|
fwrite(pdf2htmlEXTmpDir, strlen(pdf2htmlEXTmpDir), 1, stderrFile);
|
||||||
|
fwrite(ffwMessage_3, strlen(ffwMessage_3), 1, stderrFile);
|
||||||
|
} else {
|
||||||
|
fwrite(noFfwMessage, strlen(noFfwMessage), 1, stderrFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
fwrite(detailsHeader, strlen(detailsHeader), 1, stderrFile);
|
||||||
|
fwrite(detailsBody, strlen(detailsBody), 1, stderrFile);
|
||||||
|
_exit(-1);
|
||||||
|
#else
|
||||||
write(STDERR_FILENO, oopsMessage, strlen(oopsMessage) );
|
write(STDERR_FILENO, oopsMessage, strlen(oopsMessage) );
|
||||||
|
|
||||||
if (ffwAction) {
|
if (ffwAction) {
|
||||||
@ -115,7 +140,7 @@ void signalHandler(int sigInt) {
|
|||||||
write(STDERR_FILENO, detailsHeader, strlen(detailsHeader) );
|
write(STDERR_FILENO, detailsHeader, strlen(detailsHeader) );
|
||||||
write(STDERR_FILENO, detailsBody, strlen(detailsBody) );
|
write(STDERR_FILENO, detailsBody, strlen(detailsBody) );
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
@ -184,6 +209,17 @@ void setupSignalHandler(
|
|||||||
|
|
||||||
// Now setup the signal handler
|
// Now setup the signal handler
|
||||||
//
|
//
|
||||||
|
#ifdef _WIN32
|
||||||
|
signal(SIGILL, signalHandler); // Illegal Instruction
|
||||||
|
signal(SIGFPE, signalHandler); // Floating-point exception
|
||||||
|
signal(SIGSEGV, signalHandler); // Invalid memory reference
|
||||||
|
#ifdef SIGBUS
|
||||||
|
signal(SIGBUS, signalHandler);
|
||||||
|
#endif
|
||||||
|
#ifdef SIGSYS
|
||||||
|
signal(SIGSYS, signalHandler);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
memset(&act, 0, sizeof(act));
|
memset(&act, 0, sizeof(act));
|
||||||
act.sa_handler = signalHandler;
|
act.sa_handler = signalHandler;
|
||||||
//
|
//
|
||||||
@ -192,6 +228,7 @@ void setupSignalHandler(
|
|||||||
sigaction(SIGSEGV, &act, NULL); // Invalid memory reference
|
sigaction(SIGSEGV, &act, NULL); // Invalid memory reference
|
||||||
sigaction(SIGBUS, &act, NULL); // Bus error (bad memory access)
|
sigaction(SIGBUS, &act, NULL); // Bus error (bad memory access)
|
||||||
sigaction(SIGSYS, &act, NULL); // Bad system call (SVr4)
|
sigaction(SIGSYS, &act, NULL); // Bad system call (SVr4)
|
||||||
|
#endif
|
||||||
|
|
||||||
// All done
|
// All done
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user