-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalloc.h
More file actions
45 lines (38 loc) · 808 Bytes
/
alloc.h
File metadata and controls
45 lines (38 loc) · 808 Bytes
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
39
40
41
42
43
44
45
#ifndef ALLOC_H
#define ALLOC_H
#ifndef _AMALGAMATE_
#include "basedefs.h"
#include "log.h"
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#endif
AK_ALLOC static inline char* xstrdup(const char *str) {
char *ret = strdup(str);
if (!ret) {
akfatal2("Allocation failed");
}
return ret;
}
AK_ALLOC static inline void* xmalloc(size_t size) {
void *ptr = malloc(size);
if (!ptr) {
akfatal2("Allocation failed");
}
return ptr;
}
AK_ALLOC static inline void* xrealloc(void *p, size_t size) {
void *ptr = realloc(p, size);
if (!ptr) {
akfatal2("Allocation failed");
}
return ptr;
}
AK_ALLOC static inline void* xcalloc(size_t nmemb, size_t size) {
void *ptr = calloc(nmemb, size);
if (!ptr) {
akfatal2("Allocation failed");
}
return ptr;
}
#endif