/* error.c -- report an error, then die * * char *format; * error(format, arg1, arg2, ...) * * error is called like printf. It writes the specified error message * on stderr, preceded by the program name (obtained from the global * char *PROGNAME) and followed by a newline, then exits with status * ERROR. * * error1 is identical to error. It is present for the convenience of * earlier programs that were written without the varargs possibility, * and had to call a different routine to pass an argument. * * verror is the varargs version of error. It is called using: * #include * * char *format; * va_list ap; * verror(format, ap); */ #include #include #include "common.h" void error(const char *, ...); void error1(const char *, ...); void verror(const char *, va_list); extern char *PROGNAME; void error( const char *f, ... ) { va_list ap; va_start(ap, f); verror(f, ap); va_end(ap); } void error1( const char *f, ... ) { va_list ap; va_start(ap, f); verror(f, ap); va_end(ap); } void verror( const char *f, va_list ap ) { fprintf(stderr, "%s: ", PROGNAME); vfprintf(stderr, f, ap); putc('\n', stderr); perror(PROGNAME); exit(ERROR); }