blob: 81816be9db3904bc5fc57bf0d7742cd047433d49 (
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
25
26
27
28
29
30
31
32
33
|
/* See LICENSE file for copyright and license details. */
#include <stdlib.h>
#define emalloc(...) enmalloc(1, __VA_ARGS__)
#define ecalloc(...) encalloc(1, __VA_ARGS__)
#define erealloc(...) enrealloc(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, "calloc: out of memory\n");
return ptr;
}
static inline void *
enrealloc(int status, void *ptr, size_t n)
{
ptr = realloc(ptr, n);
if (!ptr)
enprintf(status, "realloc: out of memory\n");
return ptr;
}
|