No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / texinfo / lib / xmalloc.c
blob1d506c3f39742a64468162d42ab783a7cee0b3df
1 /* $NetBSD$ */
3 /* xmalloc.c -- safe versions of malloc and realloc.
5 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 2004 Free Software
6 Foundation, Inc.
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)
11 any later version.
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)
25 #include "system.h"
27 static void
28 memory_error_and_abort (const char *fname)
30 fprintf (stderr, "%s: Out of virtual memory!\n", fname);
31 abort ();
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. */
37 void *
38 xmalloc (size_t bytes)
40 void *temp = malloc (bytes);
42 if (!temp)
43 memory_error_and_abort ("xmalloc");
44 return (temp);
47 void *
48 xrealloc (void *pointer, size_t bytes)
50 void *temp;
52 if (!pointer)
53 temp = malloc (bytes);
54 else
55 temp = realloc (pointer, bytes);
57 if (!temp)
58 memory_error_and_abort ("xrealloc");
60 return (temp);
63 #endif /* !ALREADY_HAVE_XMALLOC */