1 /* xmalloc.c -- safe versions of malloc and realloc.
3 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 2004 Free Software
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 Written by Brian Fox (bfox@ai.mit.edu). */
22 #if !defined (ALREADY_HAVE_XMALLOC)
26 memory_error_and_abort (const char *fname)
28 fprintf (stderr, "%s: Out of virtual memory!\n", fname);
32 /* Return a pointer to free()able block of memory large enough
33 to hold BYTES number of bytes. If the memory cannot be allocated,
34 print an error message and abort. */
36 xmalloc (size_t bytes)
38 void *temp = malloc (bytes);
41 memory_error_and_abort ("xmalloc");
46 xrealloc (void *pointer, size_t bytes)
51 temp = malloc (bytes);
53 temp = realloc (pointer, bytes);
56 memory_error_and_abort ("xrealloc");
61 #endif /* !ALREADY_HAVE_XMALLOC */