| 1 |
greg |
1.1 |
#ifndef lint
|
| 2 |
greg |
2.8 |
static const char RCSid[] = "$Id: error.c,v 2.7 2003/02/25 02:47:21 greg Exp $";
|
| 3 |
greg |
1.1 |
#endif
|
| 4 |
|
|
/*
|
| 5 |
|
|
* error.c - standard error reporting function
|
| 6 |
greg |
2.6 |
*
|
| 7 |
|
|
* External symbols declared in standard.h
|
| 8 |
|
|
*/
|
| 9 |
|
|
|
| 10 |
greg |
2.7 |
#include "copyright.h"
|
| 11 |
greg |
1.1 |
|
| 12 |
greg |
2.8 |
#include <stdio.h>
|
| 13 |
|
|
|
| 14 |
|
|
#include "rterror.h"
|
| 15 |
greg |
1.1 |
|
| 16 |
greg |
2.6 |
extern char *strerror();
|
| 17 |
gregl |
2.4 |
/* global list of error actions */
|
| 18 |
|
|
struct erract erract[NERRS] = ERRACT_INIT;
|
| 19 |
greg |
1.1 |
|
| 20 |
greg |
2.2 |
char errmsg[512]; /* global error message buffer */
|
| 21 |
greg |
1.1 |
|
| 22 |
|
|
|
| 23 |
greg |
2.6 |
void
|
| 24 |
greg |
1.1 |
error(etype, emsg) /* report error, quit if necessary */
|
| 25 |
|
|
int etype;
|
| 26 |
|
|
char *emsg;
|
| 27 |
|
|
{
|
| 28 |
gregl |
2.4 |
register struct erract *ep;
|
| 29 |
|
|
|
| 30 |
|
|
if (etype < 0 | etype >= NERRS)
|
| 31 |
greg |
1.1 |
return;
|
| 32 |
gregl |
2.4 |
ep = erract + etype;
|
| 33 |
|
|
if (ep->pf != NULL) {
|
| 34 |
gregl |
2.5 |
if (ep->pre[0]) (*ep->pf)(ep->pre);
|
| 35 |
|
|
if (emsg != NULL && emsg[0]) (*ep->pf)(emsg);
|
| 36 |
gregl |
2.4 |
if (etype == SYSTEM && errno > 0) {
|
| 37 |
|
|
(*ep->pf)(": ");
|
| 38 |
greg |
2.6 |
(*ep->pf)(strerror(errno));
|
| 39 |
greg |
1.1 |
}
|
| 40 |
gregl |
2.4 |
(*ep->pf)("\n");
|
| 41 |
|
|
}
|
| 42 |
|
|
if (!ep->ec) /* non-fatal */
|
| 43 |
|
|
return;
|
| 44 |
|
|
if (ep->ec < 0) /* dump core */
|
| 45 |
greg |
1.1 |
abort();
|
| 46 |
gregl |
2.4 |
quit(ep->ec); /* quit calls exit after cleanup */
|
| 47 |
greg |
1.1 |
}
|