From: Martin Mares Date: Tue, 24 Jul 2012 12:10:54 +0000 (+0200) Subject: Introduced die() and NONRET X-Git-Tag: v1.0~35 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=290fee3651cae596e6fa103d342bcb2b00ebebf6;p=xsv.git Introduced die() and NONRET --- diff --git a/xsv.c b/xsv.c index 6456410..8a84bb5 100644 --- a/xsv.c +++ b/xsv.c @@ -16,15 +16,32 @@ #include +#ifdef __GNUC__ +#define NONRET __attribute__((noreturn)) +#else +#define NONRET +#endif + +/*** General functions ***/ + +static void NONRET die(char *msg, ...) +{ + va_list args; + va_start(args, msg); + fprintf(stderr, "xsv: "); + vfprintf(stderr, msg, args); + fputc('\n', stderr); + va_end(args); + exit(1); +} + /*** Memory allocation ***/ static void *xmalloc(size_t bytes) { void *p = malloc(bytes); - if (!p) { - fprintf(stderr, "xsv: Out of memory (cannot allocate %zu bytes)\n", bytes); - exit(1); - } + if (!p) + die("Out of memory (cannot allocate %zu bytes)", bytes); return p; } @@ -38,10 +55,8 @@ static void *xmalloc_zero(size_t bytes) static void *xrealloc(void *old, size_t bytes) { void *p = realloc(old, bytes); - if (!p) { - fprintf(stderr, "xsv: Out of memory (cannot allocate %zu bytes)\n", bytes); - exit(1); - } + if (!p) + die("Out of memory (cannot allocate %zu bytes)", bytes); return p; } @@ -541,7 +556,7 @@ static void two_pass(void) /*** Parsing of arguments ***/ -static void usage(void) +static void NONRET usage(void) { printf("\ Usage: xsv [] []\n\ @@ -566,7 +581,7 @@ Other options:\n\ exit(0); } -static void bad_args(const char *msg, ...) +static void NONRET bad_args(const char *msg, ...) { if (msg) { va_list args;