- New function Buf_Append(), which is given a pointer to a string to
[dragonfly.git] / contrib / gcc / cppalloc.c
1 /* Part of CPP library.  (memory allocation - xmalloc etc)
2    Copyright (C) 1986, 87, 89, 92, 93, 94, 1995, 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
6
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.
11
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.
16
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.
20
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!  */
24
25 #include "config.h"
26 #include "system.h"
27 #include "cpplib.h"
28
29 static void memory_full PROTO ((void)) ATTRIBUTE_NORETURN;
30
31 static void
32 memory_full ()
33 {
34   cpp_notice ("%s: Memory exhausted.\n", progname);
35   exit (FATAL_EXIT_CODE);
36 }
37
38 PTR
39 xmalloc (size)
40   size_t size;
41 {
42   register PTR ptr = (PTR) malloc (size);
43   if (ptr == 0)
44     memory_full ();
45   return ptr;
46 }
47
48 PTR
49 xcalloc (number, size)
50   size_t number, size;
51 {
52   register PTR ptr = (PTR) calloc (number, size);
53   if (ptr == 0)
54     memory_full ();
55   return ptr;
56 }
57
58 PTR
59 xrealloc (old, size)
60   PTR old;
61   size_t size;
62 {
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;
71 }
72
73 char *
74 xstrdup (input)
75   const char *input;
76 {
77   unsigned size = strlen (input);
78   char *output = xmalloc (size + 1);
79   strcpy (output, input);
80   return output;
81 }