aboutsummaryrefslogtreecommitdiff
path: root/util.h
blob: df602e89547a0ac10743b938e71a847a588bfe3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

#ifndef NDEBUG
static void
error(const char *msg, ...)
{
	va_list ap;

	va_start(ap, msg);
	fprintf(stderr, "Error: ");
	vfprintf(stderr, msg, ap);
	va_end(ap);
	fprintf(stderr, "\n");
	exit(EXIT_FAILURE);
}

#	define ERROR(msg) error(msg " in \"%s()\" (%s:%d)", __func__, __FILE__, __LINE__)
#else
#	define ERROR(msg) /**/
#endif

#ifndef NELEM
#	define NELEM(x) (sizeof(x) / sizeof(x[0])) /* NOLINT */
#endif