3 * File name: ir/adt/xmalloc.c
4 * Purpose: Xmalloc --- never failing wrappers for malloc() & friends.
5 * Author: Markus Armbruster
7 * Created: 1999 by getting from fiasco
9 * Copyright: (c) 1995, 1996 Markus Armbruster
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
13 /* @@@ ToDo: replace this file with the one from liberty.
14 [reimplement xstrdup, ... ] */
24 static inline __attribute__((noreturn))
25 void out_of_memory(void) {
26 panic("out of memory");
29 void *xmalloc(size_t size) {
30 void *res = malloc(size);
32 if (UNLIKELY(res == NULL))
38 void *xcalloc(size_t num, size_t size) {
39 void *res = calloc(num, size);
41 if (UNLIKELY(res == NULL))
47 void *xrealloc(void *ptr, size_t size) {
48 void *res = realloc (ptr, size);
50 if (UNLIKELY(res == NULL))
56 char *xstrdup(const char *str) {
57 size_t len = strlen(str) + 1;
58 char *res = xmalloc(len);
59 memcpy(res, str, len);