added a pseudo implementation of struvt ident to allow easy debugging
[libfirm] / ir / adt / xmalloc.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/adt/xmalloc.c
4  * Purpose:     Xmalloc --- never failing wrappers for malloc() & friends.
5  * Author:      Markus Armbruster
6  * Modified by:
7  * Created:     1999 by getting from fiasco
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1995, 1996 Markus Armbruster
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /* @@@ ToDo: replace this file with the one from liberty.
14    [reimplement xstrdup, ... ] */
15
16 #ifdef HAVE_CONFIG_H
17 # include "config.h"
18 #endif
19
20 #ifdef HAVE_ALLOCA_H
21 # include <alloca.h>
22 #endif
23 #ifdef HAVE_MALLOC_H
24 # include <malloc.h>
25 #endif
26 #ifdef HAVE_STRING_H
27 # include <string.h>
28 #endif
29 #ifdef HAVE_STDLIB_H
30 # include <stdlib.h>
31 #endif
32
33 #include "xmalloc.h"
34 #include "panic.h"
35
36 void *
37 xmalloc(size_t size) {
38   void *res = malloc (size);
39
40   if (!res) xnomem();
41   return res;
42 }
43
44 void *xcalloc(size_t num, size_t size) {
45   void *res = calloc(num, size);
46
47   if (!res) xnomem();
48   return res;
49 }
50
51 void *
52 xrealloc(void *ptr, size_t size) {
53   /* ANSI blesses realloc (0, x) but SunOS chokes on it */
54   void *res = ptr ? realloc (ptr, size) : malloc (size);
55
56   if (!res) xnomem ();
57   return res;
58 }
59
60
61 char *
62 xstrdup(const char *str) {
63   size_t len = strlen (str) + 1;
64   return memcpy ((xmalloc) (len), str, len);
65 }
66
67
68 void
69 xnomem(void) {
70   panic("out of memory");
71 }