all the autoconfig stuff
[libfirm] / ir / adt / xmalloc.c
1 /* Xmalloc --- never failing wrappers for malloc() & friends.
2    Copyright (C) 1995, 1996 Markus Armbruster */
3
4 /* @@@ ToDo: replace this file with the one from liberty.
5    [reimplement xstrdup, ... ] */
6
7 #ifdef HAVE_CONFIG_H
8 # include <config.h>
9 #endif
10
11 #include <stdlib.h>
12 #include <string.h>
13 #include "misc.h"
14 #include "panic.h"
15
16
17 void *
18 (xmalloc) (size_t size)
19 {
20   void *res = malloc (size);
21
22   if (!res) xnomem ();
23   return res;
24 }
25
26
27 void *
28 (xrealloc) (void *ptr, size_t size)
29 {
30   /* ANSI blesses realloc (0, x) but SunOS chokes on it */
31   void *res = ptr ? realloc (ptr, size) : malloc (size);
32
33   if (!res) xnomem ();
34   return res;
35 }
36
37
38 char *
39 (xstrdup) (const char *str)
40 {
41   size_t len = strlen (str) + 1;
42   return memcpy ((xmalloc) (len), str, len);
43 }
44
45
46 void
47 xnomem (void)
48 {
49   panic ("out of memory");
50 }