summaryrefslogtreecommitdiffstats
path: root/mem.h
blob: 032740cb551081a0211de537446f1f6eab271c16 (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
#ifndef MEM_H
#define MEM_H

#include <err.h>
#include <stdlib.h>

#define MALLOC(s)      xmalloc((s), __FILE__, __LINE__)
#define REALLOC(p, s)  xrealloc((p), (s), __FILE__, __LINE__)

static inline void *xmalloc(size_t s, const char *file, int line)
{
	void *p;

	if (!(p = malloc(s)))
		err(1, "%s:%d: malloc", file, line);
	return p;
}

static inline void *xrealloc(void *ptr, size_t s, const char *file, int line)
{
	void *p;

	if (!(p = realloc(ptr, s)))
		err(1, "%s:%d: realloc", file, line);
	return p;
}

#endif /* MEM_H */