blob: fa3245125b09a9832d5fc599d16a1d148032faad (
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
29
30
31
32
33
34
35
36
|
#include "memory.h"
#include <err.h>
#include <stdlib.h>
static inline void memory_exhausted(void)
{
err(1, "Memory exhausted.");
}
void *my_malloc(size_t size)
{
void *ptr = malloc(size);
if (size && !ptr)
memory_exhausted();
return ptr;
}
void *my_calloc(size_t nmemb, size_t size)
{
void *ptr = calloc(nmemb, size);
if (size && nmemb && !ptr)
memory_exhausted();
return ptr;
}
void *my_reallocarray(void *ptr, size_t nmemb, size_t size)
{
ptr = reallocarray(ptr, nmemb, size);
if (size && nmemb && !ptr)
memory_exhausted();
return ptr;
}
|