-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmy_alloc.h
77 lines (61 loc) · 1.46 KB
/
my_alloc.h
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
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef MY_ALLOC_H
#define MY_ALLOC_H
#include <assert.h>
#include <stdlib.h>
#include <string.h>
static inline void *
my_calloc(size_t nmemb, size_t size)
{
void *ptr = calloc(nmemb, size);
assert(ptr != NULL);
return (ptr);
}
static inline void *
my_malloc(size_t size)
{
void *ptr = malloc(size);
assert(ptr != NULL);
return (ptr);
}
static inline void *
my_realloc(void *ptr, size_t size)
{
ptr = realloc(ptr, size);
assert(ptr != NULL);
return (ptr);
}
static inline char *
my_strdup(const char *s)
{
char *ptr = strdup(s);
assert(ptr != NULL);
return (ptr);
}
#define my_free(ptr) do { free(ptr); (ptr) = NULL; } while (0)
#if defined(MY_ALLOC_WARN_DEPRECATED)
static inline void *my_calloc_deprecated(size_t, size_t)
__attribute__ ((deprecated("use my_calloc, not calloc")));
static inline void *my_malloc_deprecated(size_t)
__attribute__ ((deprecated("use my_malloc, not malloc")));
static inline void *my_realloc_deprecated(void *, size_t)
__attribute__ ((deprecated("use my_realloc, not realloc")));
static inline void *
my_calloc_deprecated(size_t nmemb, size_t size)
{
return calloc(nmemb, size);
}
static inline void *
my_malloc_deprecated(size_t size)
{
return malloc(size);
}
static inline void *
my_realloc_deprecated(void *ptr, size_t size)
{
return realloc(ptr, size);
}
#define calloc my_calloc_deprecated
#define malloc my_malloc_deprecated
#define realloc my_realloc_deprecated
#endif /* MY_ALLOC_WARN_DEPRECATED */
#endif /* MY_ALLOC_H */