aboutsummaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
new file mode 100644
index 0000000..7ede6fd
--- /dev/null
+++ b/src/util.h
@@ -0,0 +1,24 @@
1#pragma once
2
3#include <stdarg.h>
4#include <stdio.h>
5#include <stdlib.h>
6
7static void
8error(const char *msg, ...)
9{
10 va_list ap;
11
12 va_start(ap, msg);
13 fprintf(stderr, "Error: ");
14 vfprintf(stderr, msg, ap);
15 va_end(ap);
16 fprintf(stderr, "\n");
17 exit(EXIT_FAILURE);
18}
19
20#define ERROR(msg) error(msg " in \"%s()\" (%s:%d)", __func__, __FILE__, __LINE__)
21
22#ifndef NELEM
23# define NELEM(x) (sizeof(x) / sizeof(x[0])) /* NOLINT */
24#endif