replaced char* by idents, minor fix in Firm codegen for call
[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 #include <stdlib.h>
21 #include <string.h>
22
23 #include "xmalloc.h"
24 #include "panic.h"
25
26
27 void *
28 (xmalloc) (size_t size)
29 {
30   void *res = malloc (size);
31
32   if (!res) xnomem ();
33
34   memset (res, 0x00, size);
35
36   return res;
37 }
38
39
40 void *
41 (xrealloc) (void *ptr, size_t size)
42 {
43   /* ANSI blesses realloc (0, x) but SunOS chokes on it */
44   void *res = ptr ? realloc (ptr, size) : malloc (size);
45
46   if (!res) xnomem ();
47
48   return res;
49 }
50
51
52 char *
53 (xstrdup) (const char *str)
54 {
55   size_t len = strlen (str) + 1;
56   return memcpy ((xmalloc) (len), str, len);
57 }
58
59
60 void
61 xnomem (void)
62 {
63   panic ("out of memory");
64 }