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