aboutsummaryrefslogtreecommitdiff
path: root/include/macros.h
blob: 6adc1e447af7ebc5565473e637c1cdf77261c0e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef MLIB_MACROS_H
#define MLIB_MACROS_H

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define lengthof(a) (sizeof(a) / sizeof(*(a)))

#define memeq(x, y, n)   (!memcmp(x, y, n))
#define streq(x, y)      (!strcmp(x, y))
#define u8eq(x, n, y, m) (!u8cmp(x, n, y, m))

#ifdef NDEBUG
#	include <stddef.h>
#	define ASSUME(p) ((p) ? (void)0 : unreachable())
#else
#	include "errors.h"
#	define ASSUME(p) \
		((p) ? (void)0 \
		     : warnx("%s:%s:%d: assumption ‘%s’ failed", __FILE__, __func__, \
		             __LINE__, #p))
#endif

#endif /* !MLIB_MACROS_H */