diff options
author | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2001-06-15 11:21:35 +0000 |
---|---|---|
committer | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2001-06-15 11:21:35 +0000 |
commit | 5768b2b0601e52f4560105f5109ecbe089d692da (patch) | |
tree | 7fba57039fcae2acfd7faff525e854d120db37c4 /src/jtutil/error_exit.c | |
parent | 68d60d17cd97a0ad65943dbe4c4b9c7874635a4b (diff) |
initial import into cvs
git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@19 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src/jtutil/error_exit.c')
-rw-r--r-- | src/jtutil/error_exit.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/jtutil/error_exit.c b/src/jtutil/error_exit.c new file mode 100644 index 0000000..26acdf7 --- /dev/null +++ b/src/jtutil/error_exit.c @@ -0,0 +1,48 @@ +/* error_exit -- print an error message and exit */ +/* $Id$ */ +/* + * error_exit -- print an error message and exit + */ + +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> + +#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 + * <jt/stdc.h>) 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*/ +} |