-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathxmalloc.h
31 lines (25 loc) · 829 Bytes
/
xmalloc.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
#ifndef XMALLOC_H
#define XMALLOC_H
#ifdef __cplusplus
extern "C"
{
#endif
void *xmalloc(size_t size);
void *xmalloc0(size_t size);
void *xcalloc(size_t num, size_t size);
void *xrealloc(void *ptr, size_t newsize);
char *xstrdup(const char *s);
char *xstrduplower(const char *s);
char *xstrdupdelim(const char *beg, const char *end);
void xfree(void *ptr);
void xfreenull(void **ptr);
#ifdef __cplusplus
}
#endif
#define xnew(type) ((type *) xmalloc (sizeof (type)))
#define xnew0(type) ((type *) xmalloc0 (sizeof (type)))
#define xnew_array(type, len) ((type *) xmalloc ((len) * sizeof (type)))
#define xnew0_array(type, len) ((type *) xmalloc0 ((len) * sizeof (type)))
#define alloca_array(type, size) ((type *) alloca ((size) * sizeof (type)))
#define xfree_null(p) if (!(p)) ; else xfree (p)
#endif