| 1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* error.c - standard error reporting function |
| 6 |
+ |
* |
| 7 |
+ |
* External symbols declared in standard.h |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
< |
#include "standard.h" |
| 10 |
> |
#include "copyright.h" |
| 11 |
|
|
| 12 |
< |
extern char *sys_errlist[]; /* system error list */ |
| 13 |
< |
extern int sys_nerr; /* number of system errors */ |
| 12 |
> |
#include <stdio.h> |
| 13 |
> |
#include <stdlib.h> |
| 14 |
|
|
| 15 |
< |
char errmsg[512]; /* global error message buffer */ |
| 15 |
> |
#include "rterror.h" |
| 16 |
|
|
| 17 |
+ |
extern char *strerror(int); |
| 18 |
+ |
/* global list of error actions */ |
| 19 |
+ |
struct erract erract[NERRS] = ERRACT_INIT; |
| 20 |
|
|
| 21 |
< |
error(etype, emsg) /* report error, quit if necessary */ |
| 22 |
< |
int etype; |
| 23 |
< |
char *emsg; |
| 21 |
> |
char errmsg[2048]; /* global error message buffer */ |
| 22 |
> |
|
| 23 |
> |
|
| 24 |
> |
void |
| 25 |
> |
error(int etype, const char *emsg) /* report error, quit if necessary */ |
| 26 |
|
{ |
| 27 |
< |
switch (etype) { |
| 28 |
< |
case WARNING: |
| 29 |
< |
wputs("warning - "); |
| 26 |
< |
wputs(emsg); |
| 27 |
< |
wputs("\n"); |
| 27 |
> |
struct erract *ep; |
| 28 |
> |
|
| 29 |
> |
if ((etype < 0) | (etype >= NERRS)) |
| 30 |
|
return; |
| 31 |
< |
case COMMAND: |
| 32 |
< |
cputs(emsg); |
| 33 |
< |
cputs("\n"); |
| 34 |
< |
return; |
| 35 |
< |
case USER: |
| 36 |
< |
eputs("fatal - "); |
| 37 |
< |
eputs(emsg); |
| 36 |
< |
eputs("\n"); |
| 37 |
< |
quit(1); |
| 38 |
< |
case INTERNAL: |
| 39 |
< |
eputs("internal - "); |
| 40 |
< |
eputs(emsg); |
| 41 |
< |
eputs("\n"); |
| 42 |
< |
quit(1); |
| 43 |
< |
case SYSTEM: |
| 44 |
< |
eputs("system - "); |
| 45 |
< |
eputs(emsg); |
| 46 |
< |
if (errno > 0) { |
| 47 |
< |
eputs(": "); |
| 48 |
< |
if (errno <= sys_nerr) |
| 49 |
< |
eputs(sys_errlist[errno]); |
| 50 |
< |
else |
| 51 |
< |
eputs("Unknown error"); |
| 31 |
> |
ep = erract + etype; |
| 32 |
> |
if (ep->pf != NULL) { |
| 33 |
> |
if (ep->pre[0]) (*ep->pf)(ep->pre); |
| 34 |
> |
if (emsg != NULL && emsg[0]) (*ep->pf)(emsg); |
| 35 |
> |
if (etype == SYSTEM && errno > 0) { |
| 36 |
> |
(*ep->pf)(": "); |
| 37 |
> |
(*ep->pf)(strerror(errno)); |
| 38 |
|
} |
| 39 |
< |
eputs("\n"); |
| 54 |
< |
quit(2); |
| 55 |
< |
case CONSISTENCY: |
| 56 |
< |
eputs("consistency - "); |
| 57 |
< |
eputs(emsg); |
| 58 |
< |
eputs("\n"); |
| 59 |
< |
abort(); |
| 39 |
> |
(*ep->pf)("\n"); |
| 40 |
|
} |
| 41 |
+ |
if (!ep->ec) /* non-fatal */ |
| 42 |
+ |
return; |
| 43 |
+ |
if (ep->ec < 0) /* dump core */ |
| 44 |
+ |
abort(); |
| 45 |
+ |
quit(ep->ec); /* quit calls exit after cleanup */ |
| 46 |
|
} |