Last change
on this file was
2,
checked in by oldcode, 24 years ago
|
Initial revision
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
File size:
802 bytes
|
Line | |
---|
1 | /* xmalloc.h --- never-fail memory allocators. |
---|
2 | Jim Blandy <jimb@gnu.ai.mit.edu> --- July 1994 */ |
---|
3 | |
---|
4 | #include <stddef.h> |
---|
5 | #include <stdlib.h> |
---|
6 | #include <stdio.h> |
---|
7 | |
---|
8 | /* Under FreeBSD 1.1.5.1, it is unfortunately necessary to #include |
---|
9 | this after <stdio.h>, because <malloc.h> assumes that, if you're |
---|
10 | using an ANSI C compiler, the FILE typedef will be defined. Rah. */ |
---|
11 | #include "xmalloc.h" |
---|
12 | |
---|
13 | #ifdef __GNUC__ |
---|
14 | #define INLINE inline |
---|
15 | #else |
---|
16 | #define INLINE |
---|
17 | #endif |
---|
18 | |
---|
19 | static INLINE void * |
---|
20 | check_ptr (void *p) |
---|
21 | { |
---|
22 | if (! p) |
---|
23 | { |
---|
24 | fprintf (stderr, "out of memory\n"); |
---|
25 | exit (2); |
---|
26 | } |
---|
27 | else |
---|
28 | return p; |
---|
29 | } |
---|
30 | |
---|
31 | void * |
---|
32 | xmalloc (size_t n) |
---|
33 | { |
---|
34 | return check_ptr (malloc (n)); |
---|
35 | } |
---|
36 | |
---|
37 | void * |
---|
38 | xrealloc (void *p, size_t n) |
---|
39 | { |
---|
40 | if (p) |
---|
41 | return check_ptr (realloc (p, n)); |
---|
42 | else |
---|
43 | return check_ptr (malloc (n)); |
---|
44 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.