/* error.c - From Jon C. Snader: Effective TCP/IP Programming * Addison-Wesley 2000 * For better understanding, read the excellent Snader book. */ #include "etcp.h" char *program_name; /* error - print a diagnostic and optionally quit. The "..." arguments are printed out using the format fmt. if "err" is a standard error number and not 0, the correspondin standard error message is printed out. If "status" is not 0, the program exits. */ void error( int status, int err, char *fmt, ... ) { va_list ap; va_start( ap, fmt ); fprintf( stderr, "%s: ", program_name ); vfprintf( stderr, fmt, ap ); va_end( ap ); if ( err ) fprintf( stderr, ": %s (%d)\n", strerror( err ), err ); if ( status ) EXIT( status ); }