blob: ad7228e0eeb34cc6a38f36cb4d3f0b07af704a5b (
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
|
#include <helpers.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void die(const char *msg) {
fprintf(stderr, "panic: ");
perror(msg);
exit(EXIT_FAILURE);
}
void *safe_calloc(unsigned int i, size_t size) {
void *x = calloc(i, size);
if (x == NULL) {
die("abort: calloc()");
}
return x;
}
void *safe_realloc(void *x, size_t size) {
void *p = realloc(x, size);
if (x == NULL) {
die("abort: realloc()");
}
return p;
}
void alloc_zero(void *ptr, size_t size) { memset(ptr, 0, size); }
|