aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/emalloc.h
blob: 7c4266eafe8aa8f56fdd027bc265502e0849b6c5 (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
/* See LICENSE file for copyright and license details. */
#include <stdlib.h>

#define emalloc(...) enmalloc(1, __VA_ARGS__)
#define ecalloc(...) encalloc(1, __VA_ARGS__)

static inline void *
enmalloc(int status, size_t n)
{
	void *ptr = malloc(n);
	if (!ptr)
		enprintf(status, "malloc: out of memory\n");
	return ptr;
}

static inline void *
encalloc(int status, size_t n, size_t m)
{
	void *ptr = calloc(n, m);
	if (!ptr)
		enprintf(status, "malloc: out of memory\n");
	return ptr;
}