**************************************************************************/
#include <windows.h>
+#include <signal.h>
#include <string.h>
#include <stdio.h>
va_end(ap);
OutputDebugStringA(buf);
+
+ /*
+ * Also write the message to stderr, when a debugger is not present (to
+ * avoid duplicate messages in command line debuggers).
+ */
+#if _WIN32_WINNT > 0x0400
if (!IsDebuggerPresent()) {
fflush(stdout);
fputs(buf, stderr);
fflush(stderr);
}
+#endif
}
long long GetTime(void)
{
static LARGE_INTEGER frequency;
LARGE_INTEGER counter;
- if(!frequency.QuadPart)
+ if (!frequency.QuadPart)
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&counter);
return counter.QuadPart*1000000LL/frequency.QuadPart;
#endif
}
+
+struct Interrupts
+{
+ Interrupts()
+ : set(false),
+ prevfilter(NULL),
+ handler(NULL)
+ {}
+
+ bool set;
+ LPTOP_LEVEL_EXCEPTION_FILTER prevFilter;
+
+ void (*handler)(int);
+};
+static Interrupts interrupts;
+
+LONG WINAPI InterruptHandler(EXCEPTION_POINTERS *exceptionInfo)
+{
+ if (interrupts.handler) {
+ int exceptionCode = 0;
+ if (exceptionInfo) {
+ exceptionCode = exceptionInfo->ExceptionRecord.ExceptionCode;
+ }
+
+ interrupts.handler(exceptionCode);
+ }
+
+ if (interrupts.prevFilter) {
+ return interrupts.prevFilter(exceptionInfo);
+ } else {
+ return EXCEPTION_CONTINUE_SEARCH;
+ }
+}
+
+void
+CatchInterrupts(void (*func)(int))
+{
+ interrupts.handler = func;
+
+ if (!interrupts.set) {
+ interrupts.prevFilter =
+ SetUnhandledExceptionFilter(InterruptHandler);
+ interrupts.set = true;
+ }
+}
+
+
} /* namespace OS */