1 |
tdb |
1.1 |
/* panic.c -- Call a user user-defined panic handling routine and abort() */ |
2 |
|
|
|
3 |
|
|
/* Copyright 1992 Godfrey Paul, University of Kent at Canterbury. |
4 |
|
|
* |
5 |
|
|
* You can do what you like with this source code as long as |
6 |
|
|
* you don't try to make money out of it and you include an |
7 |
|
|
* unaltered copy of this message (including the copyright). |
8 |
|
|
*/ |
9 |
|
|
|
10 |
tdb |
1.2 |
char ukcprog_panic_sccsid[] = "$Id: panic.c,v 1.1 2002/03/08 14:37:29 tdb Exp $ UKC"; |
11 |
tdb |
1.1 |
|
12 |
|
|
#include <stdio.h> |
13 |
|
|
#include <stdlib.h> |
14 |
|
|
|
15 |
|
|
#include "ukcprog.h" |
16 |
|
|
|
17 |
|
|
|
18 |
|
|
static panic_handler_t User_panic_handler = NULL; |
19 |
|
|
|
20 |
|
|
|
21 |
|
|
/* |
22 |
|
|
* install_panic_handler() |
23 |
|
|
* Installs a new panic handler, returns the old one. |
24 |
|
|
*/ |
25 |
|
|
panic_handler_t |
26 |
|
|
install_panic_handler(handler) |
27 |
|
|
panic_handler_t handler; |
28 |
|
|
{ |
29 |
|
|
panic_handler_t old; |
30 |
|
|
|
31 |
|
|
old = User_panic_handler; |
32 |
|
|
User_panic_handler = handler; |
33 |
|
|
|
34 |
|
|
return old; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
/* |
39 |
|
|
* panic() |
40 |
|
|
* Called when the world has ended. If a user-defined routine exists, |
41 |
|
|
* call it with the given message as an argument. If not, or if it |
42 |
|
|
* returns, print a suitable message and abort. |
43 |
|
|
*/ |
44 |
|
|
void |
45 |
|
|
panic(message) |
46 |
|
|
const char *message; |
47 |
|
|
{ |
48 |
|
|
if (User_panic_handler != NULL) |
49 |
|
|
(*User_panic_handler)(message); |
50 |
|
|
|
51 |
|
|
fprintf(stderr, "Fatal internal error: %s (aborting) ...\n", message); |
52 |
|
|
fflush(stderr); |
53 |
|
|
abort(); |
54 |
|
|
} |