1 /* xmalloc.c -- safe versions of malloc and realloc */
3 /* This file is part of GNU Info, a program for reading online documentation
6 This file has appeared in prior works by the Free Software Foundation;
7 thus it carries copyright dates from 1988 through 1993.
9 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993 Free Software
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 Written by Brian Fox (bfox@ai.mit.edu). */
28 #if !defined (ALREADY_HAVE_XMALLOC)
30 #include <sys/types.h>
32 extern void *malloc (), *realloc ();
33 static void memory_error_and_abort ();
35 /* **************************************************************** */
37 /* Memory Allocation and Deallocation. */
39 /* **************************************************************** */
41 /* Return a pointer to free()able block of memory large enough
42 to hold BYTES number of bytes. If the memory cannot be allocated,
43 print an error message and abort. */
48 void *temp
= malloc (bytes
);
51 memory_error_and_abort ("xmalloc");
56 xrealloc (pointer
, bytes
)
63 temp
= malloc (bytes
);
65 temp
= realloc (pointer
, bytes
);
68 memory_error_and_abort ("xrealloc");
74 memory_error_and_abort (fname
)
77 fprintf (stderr
, "%s: Out of virtual memory!\n", fname
);
80 #endif /* !ALREADY_HAVE_XMALLOC */