-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_util.c
38 lines (33 loc) · 800 Bytes
/
c_util.c
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
37
38
#ifndef C_UTIL_C
#define C_UTIL_C
#include <stdio.h>
#include <stdlib.h>
static void *
util_malloc(size_t size) {
void *p;
if ((p = malloc(size)) == NULL) {
fprintf(stderr, "Failed to allocate %zu bytes.\n", size);
exit(EXIT_FAILURE);
}
return p;
}
static void *
util_realloc(void *old, size_t size) {
void *p;
if ((p = realloc(old, size)) == NULL) {
fprintf(stderr, "Failed to allocate %zu bytes.\n", size);
exit(EXIT_FAILURE);
}
return p;
}
static void *
util_calloc(size_t nmemb, size_t size) {
void *p;
if ((p = calloc(nmemb, size)) == NULL) {
fprintf(stderr, "Failed to allocate %zu members of %zu bytes each.\n",
nmemb, size);
exit(EXIT_FAILURE);
}
return p;
}
#endif