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, ... ] */
36 xmalloc(size_t size) {
37 void *res = malloc (size);
43 void *xcalloc(size_t num, size_t size) {
44 void *res = calloc(num, size);
51 xrealloc(void *ptr, size_t size) {
52 /* ANSI blesses realloc (0, x) but SunOS chokes on it */
53 void *res = ptr ? realloc (ptr, size) : malloc (size);
61 xstrdup(const char *str) {
62 size_t len = strlen (str) + 1;
63 return memcpy ((xmalloc) (len), str, len);
69 panic("out of memory");