* Makefile.in (ggc-common.o): Depend on genrtl.h.
[official-gcc.git] / gcc / cppalloc.c
blob47712e7a1ae28e55c73e2a4bcf124b5b6d54c0da
1 /* Part of CPP library. (memory allocation - xmalloc etc)
2 Copyright (C) 1986, 87, 89, 92-95, 1998 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994.
4 Based on CCCP program by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding! */
25 #include "config.h"
26 #include "system.h"
27 #include "cpplib.h"
29 static void memory_full PROTO ((void)) ATTRIBUTE_NORETURN;
31 static void
32 memory_full ()
34 cpp_notice ("%s: Memory exhausted.\n", progname);
35 exit (FATAL_EXIT_CODE);
38 PTR
39 xmalloc (size)
40 size_t size;
42 register PTR ptr = (PTR) malloc (size);
43 if (ptr == 0)
44 memory_full ();
45 return ptr;
48 PTR
49 xcalloc (number, size)
50 size_t number, size;
52 register PTR ptr = (PTR) calloc (number, size);
53 if (ptr == 0)
54 memory_full ();
55 return ptr;
58 PTR
59 xrealloc (old, size)
60 PTR old;
61 size_t size;
63 register PTR ptr;
64 if (old)
65 ptr = (PTR) realloc (old, size);
66 else
67 ptr = (PTR) malloc (size);
68 if (ptr == 0)
69 memory_full ();
70 return ptr;
73 char *
74 xstrdup (input)
75 const char *input;
77 size_t size = strlen (input) + 1;
78 char *output = xmalloc (size);
79 memcpy (output, input, size);
80 return output;