$OpenBSD: patch-src_tools_c,v 1.5 2014/12/26 08:42:02 benoit Exp $
--- src/tools.c.orig	Wed Dec 24 20:21:37 2014
+++ src/tools.c	Thu Dec 25 07:51:07 2014
@@ -6,6 +6,7 @@
 
 #include <NTL/new.h>
 
+#include <cstdio>
 
 void _ntl_abort_cxx_callback()
 {
@@ -17,9 +18,34 @@
 
 NTL_THREAD_LOCAL void (*ErrorCallback)() = 0;
 
+/*
+  The following code differs from vanilla NTL 5.4.2.
 
+   We add a SetErrorCallbackFunction(). This sets a global callback function _function_,
+   which gets called with parameter _context_ and an error message string whenever Error()
+   gets called.
+
+   Note that if the custom error handler *returns*, then NTL will dump the error message
+   back to stderr and abort() as it habitually does.
+
+   -- David Harvey (2008-04-12)
+*/
+
+void (*ErrorCallbackFunction)(const char*, void*) = NULL;
+void *ErrorCallbackContext = NULL;
+
+
+void SetErrorCallbackFunction(void (*function)(const char*, void*), void *context)
+{
+   ErrorCallbackFunction = function;
+   ErrorCallbackContext = context;
+}
+ 
 void TerminalError(const char *s)
 {
+   if (ErrorCallbackFunction != NULL)
+       ErrorCallbackFunction(s, ErrorCallbackContext);
+
    cerr << s << "\n";
    _ntl_abort();
 }
