Selaa lähdekoodia

Add G_fatal_longjmp()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@60590 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 11 vuotta sitten
vanhempi
commit
61495c0a91
2 muutettua tiedostoa jossa 17 lisäystä ja 0 poistoa
  1. 2 0
      include/defs/gis.h
  2. 15 0
      lib/gis/error.c

+ 2 - 0
include/defs/gis.h

@@ -60,6 +60,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
+#include <setjmp.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -217,6 +218,7 @@ void G_create_alt_env(void);
 void G_switch_env(void);
 
 /* error.c */
+jmp_buf *G_fatal_longjmp(int);
 int G_info_format(void);
 void G_message(const char *, ...) __attribute__ ((format(printf, 1, 2)));
 void G_verbose_message(const char *, ...)

+ 15 - 0
lib/gis/error.c

@@ -14,6 +14,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <setjmp.h>
 #include <unistd.h>
 #include <time.h>
 #include <stdarg.h>
@@ -57,6 +58,15 @@ static void mail_msg(const char *, int);
 static int write_error(const char *, int, time_t, const char *);
 static void log_error(const char *, int);
 
+static int fatal_longjmp;
+static jmp_buf fatal_jmp_buf;
+
+jmp_buf *G_fatal_longjmp(int enable)
+{
+    fatal_longjmp = enable;
+    return &fatal_jmp_buf;
+}
+
 static void vfprint_error(int type, const char *template, va_list ap)
 {
     char buffer[2000];		/* G_asprintf does not work */
@@ -158,6 +168,11 @@ void G_fatal_error(const char *msg, ...)
         va_end(ap);
     }
 
+    if (fatal_longjmp) {
+	busy = 0;
+	longjmp(fatal_jmp_buf, 1);
+    }
+
     G__call_error_handlers();
 
     /* Raise SIGABRT, useful for debugging only.