-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsimta_malloc.c
65 lines (49 loc) · 951 Bytes
/
simta_malloc.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright (c) Regents of The University of Michigan
* See COPYING.
*/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include "simta_malloc.h"
#ifdef HAVE_JEMALLOC
#include <jemalloc/jemalloc.h>
#endif /* HAVE_JEMALLOC */
void *
simta_malloc(size_t size) {
void *p;
size = (size > 0) ? size : 1;
if ((p = malloc(size)) == NULL) {
abort();
}
return p;
}
void *
simta_calloc(size_t n, size_t size) {
void *p;
n = (n > 0) ? n : 1;
size = (size > 0) ? size : 1;
if ((p = calloc(n, size)) == NULL) {
abort();
}
return p;
}
void *
simta_realloc(void *oldp, size_t size) {
void *p;
if ((p = realloc(oldp, size)) == NULL) {
abort();
}
return p;
}
char *
simta_strdup(const char *s) {
char *p;
size_t len;
len = strlen(s) + 1;
if ((p = malloc(len)) == NULL) {
abort();
}
memcpy(p, s, len);
return p;
}