13 __hidden
void *xmalloc(size_t size
)
17 panic("xmalloc: zero size\n");
20 panic("xmalloc: out of memory (allocating %zu bytes)\n", size
);
24 __hidden
void *xzmalloc(size_t size
)
28 panic("xzmalloc: zero size\n");
31 panic("xzmalloc: out of memory (allocating %zu bytes)\n", size
);
36 __hidden
void *xmalloc_aligned(size_t size
, size_t alignment
)
41 panic("xmalloc_aligned: zero size\n");
42 ret
= posix_memalign(&ptr
, alignment
, size
);
44 panic("xmalloc_aligned: out of memory (allocating %zu bytes)\n",
49 __hidden
void *xrealloc(void *ptr
, size_t nmemb
, size_t size
)
52 size_t new_size
= nmemb
* size
;
53 if (unlikely(new_size
== 0))
54 panic("xrealloc: zero size\n");
55 if (unlikely(((size_t) ~0) / nmemb
< size
))
56 panic("xrealloc: nmemb * size > SIZE_T_MAX\n");
58 new_ptr
= malloc(new_size
);
60 new_ptr
= realloc(ptr
, new_size
);
61 if (unlikely(new_ptr
== NULL
))
62 panic("xrealloc: out of memory (new_size %zu bytes)\n",
67 __hidden
void xfree(void *ptr
)
70 panic("xfree: NULL pointer given as argument\n");
74 __hidden
char *xstrdup(const char *str
)
78 len
= strlen(str
) + 1;
80 strlcpy(cp
, str
, len
);