/* error_exit -- print an error message and exit */ /* $Id$ */ /* * error_exit -- print an error message and exit */ #include #include #include #include "stdc.h" /*****************************************************************************/ /* * This function prints an error message (formatted via vfprintf(3S)), * then exits. It does *not* return to its caller. Normally the exit * is done via exit(2), but optionally it may be done via abort(2) to * produce a core dump. Despite not actually returning, this function * is declared as returning an int , so it may be easily used in * conditional expressions like * foo = bar_ok ? baz(bar) : error_exit(...); * * Usage: * error_exit(exit_code, message, args...) * * ***** THIS VERSION IS FOR ANSI/ISO C ***** * * Arguments: * exit_code = (in) Exit code for exit(2), or PANIC_EXIT (defined in * ) to abort(2) instead. * format = (in) vprintf(3S) format string for error message to be printed. * args... = (in) Any additional arguments are (presumably) used in formatting * the error message string. */ /*VARARGS*/ int error_exit(const int exit_code, const char *const format, ...) { va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); if (exit_code == PANIC_EXIT) then abort(); /*NOTREACHED*/ else exit(exit_code); /*NOTREACHED*/ }