| 1 |
greg |
1.1 |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
|
|
|
| 3 |
|
|
#ifndef lint |
| 4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
| 5 |
|
|
#endif |
| 6 |
|
|
|
| 7 |
|
|
/* |
| 8 |
|
|
* error.c - standard error reporting function |
| 9 |
|
|
*/ |
| 10 |
|
|
|
| 11 |
|
|
#include "standard.h" |
| 12 |
|
|
|
| 13 |
gregl |
2.3 |
#ifndef linux |
| 14 |
greg |
1.1 |
extern char *sys_errlist[]; /* system error list */ |
| 15 |
|
|
extern int sys_nerr; /* number of system errors */ |
| 16 |
gregl |
2.3 |
#endif |
| 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 |
|
|
error(etype, emsg) /* report error, quit if necessary */ |
| 24 |
|
|
int etype; |
| 25 |
|
|
char *emsg; |
| 26 |
|
|
{ |
| 27 |
gregl |
2.4 |
register struct erract *ep; |
| 28 |
|
|
|
| 29 |
|
|
if (etype < 0 | etype >= NERRS) |
| 30 |
greg |
1.1 |
return; |
| 31 |
gregl |
2.4 |
ep = erract + etype; |
| 32 |
|
|
if (ep->pf != NULL) { |
| 33 |
gregl |
2.5 |
if (ep->pre[0]) (*ep->pf)(ep->pre); |
| 34 |
|
|
if (emsg != NULL && emsg[0]) (*ep->pf)(emsg); |
| 35 |
gregl |
2.4 |
if (etype == SYSTEM && errno > 0) { |
| 36 |
|
|
(*ep->pf)(": "); |
| 37 |
greg |
1.1 |
if (errno <= sys_nerr) |
| 38 |
gregl |
2.4 |
(*ep->pf)(sys_errlist[errno]); |
| 39 |
greg |
1.1 |
else |
| 40 |
gregl |
2.4 |
(*ep->pf)("Unknown error"); |
| 41 |
greg |
1.1 |
} |
| 42 |
gregl |
2.4 |
(*ep->pf)("\n"); |
| 43 |
|
|
} |
| 44 |
|
|
if (!ep->ec) /* non-fatal */ |
| 45 |
|
|
return; |
| 46 |
|
|
if (ep->ec < 0) /* dump core */ |
| 47 |
greg |
1.1 |
abort(); |
| 48 |
gregl |
2.4 |
quit(ep->ec); /* quit calls exit after cleanup */ |
| 49 |
greg |
1.1 |
} |