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