#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;
}
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;
}
/*** Parsing of arguments ***/
-static void usage(void)
+static void NONRET usage(void)
{
printf("\
Usage: xsv <in-format> [<out-format>] <options> [<fields>]\n\
exit(0);
}
-static void bad_args(const char *msg, ...)
+static void NONRET bad_args(const char *msg, ...)
{
if (msg) {
va_list args;