2 * transsip - the telephony toolkit
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011, 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
21 __hidden
void *xmalloc(size_t size
)
26 panic("xmalloc: zero size\n");
30 panic("xmalloc: out of memory (allocating %zu bytes)\n", size
);
35 __hidden
void *xzmalloc(size_t size
)
40 panic("xzmalloc: zero size\n");
44 panic("xzmalloc: out of memory (allocating %zu bytes)\n", size
);
51 __hidden
void *xmalloc_aligned(size_t size
, size_t alignment
)
57 panic("xmalloc_aligned: zero size\n");
59 ret
= posix_memalign(&ptr
, alignment
, size
);
61 panic("xmalloc_aligned: out of memory (allocating %zu bytes)\n",
67 __hidden
void *xrealloc(void *ptr
, size_t nmemb
, size_t size
)
70 size_t new_size
= nmemb
* size
;
72 if (unlikely(new_size
== 0))
73 panic("xrealloc: zero size\n");
75 if (unlikely(((size_t) ~0) / nmemb
< size
))
76 panic("xrealloc: nmemb * size > SIZE_T_MAX\n");
79 new_ptr
= malloc(new_size
);
81 new_ptr
= realloc(ptr
, new_size
);
83 if (unlikely(new_ptr
== NULL
))
84 panic("xrealloc: out of memory (new_size %zu bytes)\n",
90 __hidden
void xfree(void *ptr
)
93 panic("xfree: NULL pointer given as argument\n");
98 __hidden
char *xstrdup(const char *str
)
103 len
= strlen(str
) + 1;
105 strlcpy(cp
, str
, len
);