|
|
#include "types.h" /* for HAVE_VPRINTF */ | #include "types.h" /* for HAVE_VPRINTF */ |
#include "error.h" | #include "error.h" |
#include <stdio.h> | #include <stdio.h> |
#include <varargs.h> |
#include <stdarg.h> |
| |
#if defined(lint) && !defined(LINT_ANYWAY) | #if defined(lint) && !defined(LINT_ANYWAY) |
| |
|
|
/* VARARGS1 ARGSUSED */ | /* VARARGS1 ARGSUSED */ |
void panic(fmt) char *fmt; { exit(1); /* NOTREACHED */ } | void panic(fmt) char *fmt; { exit(1); /* NOTREACHED */ } |
| |
#else lint |
#else /* lint */ |
| |
extern char *ProgName; /* program name from argv[0] */ | extern char *ProgName; /* program name from argv[0] */ |
extern int errno; /* Unix system-call error */ |
|
extern char *sys_errlist[]; /* table of error number => string */ |
|
extern int sys_nerr; /* size of table */ |
|
| |
static FILE *trap_file; /* error diversion file, if any */ | static FILE *trap_file; /* error diversion file, if any */ |
static void (*trap_fn)(); /* trap function */ | static void (*trap_fn)(); /* trap function */ |
|
|
(void) _doprnt(fmt, l, fp); | (void) _doprnt(fmt, l, fp); |
#endif | #endif |
if (e) { | if (e) { |
if (e < sys_nerr) |
(void) fprintf(fp, ": %s", strerror(e)); |
(void) fprintf(fp, ": %s", sys_errlist[e]); |
|
else |
|
(void) fprintf(fp, ": Unknown error code %d", e); |
|
} | } |
(void) putc('\n', fp); | (void) putc('\n', fp); |
(void) fflush(fp); | (void) fflush(fp); |
|
|
* Print an error message and optionally quit. | * Print an error message and optionally quit. |
*/ | */ |
void | void |
error(va_alist) |
error(int quit, int e, const char *fmt, ...) |
va_dcl |
|
{ | { |
va_list l; | va_list l; |
int quit, e; |
|
char *fmt; |
|
| |
va_start(l); |
va_start(l, fmt); |
quit = va_arg(l, int); |
|
if ((e = va_arg(l, int)) < 0) |
|
e = errno; |
|
fmt = va_arg(l, char *); |
|
verror(quit, (char *)NULL, fmt, l, e); | verror(quit, (char *)NULL, fmt, l, e); |
va_end(l); | va_end(l); |
} | } |
|
|
* Panic (print to stderr and abort). | * Panic (print to stderr and abort). |
*/ | */ |
void | void |
panic(va_alist) |
panic(const char *fmt, ...) |
va_dcl |
|
{ | { |
va_list l; | va_list l; |
char *fmt; |
|
| |
SetErrorTrap((void (*)())NULL); /* shut down any trap */ | SetErrorTrap((void (*)())NULL); /* shut down any trap */ |
va_start(l); |
va_start(l, fmt); |
fmt = va_arg(l, char *); |
|
verror(0, "panic: ", fmt, l, 0); | verror(0, "panic: ", fmt, l, 0); |
va_end(l); | va_end(l); |
abort(); | abort(); |