chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / epp / cppalloc.c
1 /* Part of CPP library.  (memory allocation - xmalloc etc)
2  * Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
3  * Written by Per Bothner, 1994.
4  * Based on CCCP program by 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, 675 Mass Ave, Cambridge, MA 02139, 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 <stdlib.h>
26 #include "config.h"
27 #include "cpplib.h"
28
29 static void
30 memory_full(void)
31 {
32    cpp_fatal("Memory exhausted.");
33 }
34
35 void               *
36 xmalloc(unsigned size)
37 {
38    char               *ptr = (char *)malloc(size);
39
40    if (ptr != 0)
41       return (ptr);
42    memory_full();
43    /*NOTREACHED */
44    return 0;
45 }
46
47 void               *
48 xrealloc(void *old, unsigned size)
49 {
50    char               *ptr = (char *)realloc(old, size);
51
52    if (ptr == 0)
53       memory_full();
54    return ptr;
55 }
56
57 void               *
58 xcalloc(unsigned number, unsigned size)
59 {
60    char               *ptr = (char *)calloc(number, size);
61
62    if (ptr == 0)
63       memory_full();
64    return ptr;
65 }