]> mj.ucw.cz Git - xsv.git/commitdiff
Introduced die() and NONRET
authorMartin Mares <mj@ucw.cz>
Tue, 24 Jul 2012 12:10:54 +0000 (14:10 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 24 Jul 2012 12:10:54 +0000 (14:10 +0200)
xsv.c

diff --git a/xsv.c b/xsv.c
index 6456410b4eebd32162912cae3de45203d66e8cde..8a84bb5bf84936ad177eef1dc14a4c1cbd1ea77d 100644 (file)
--- a/xsv.c
+++ b/xsv.c
 
 #include <pcre.h>
 
+#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 <in-format> [<out-format>] <options> [<fields>]\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;