* rtl.h (rtunion_def): Constify member `rtstr'.
[official-gcc.git] / texinfo / lib / xmalloc.c
blob156989ed7118bfc13e42a7a68cf666f49b687781
1 /* xmalloc.c -- safe versions of malloc and realloc */
3 /* This file is part of GNU Info, a program for reading online documentation
4 stored in Info format.
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
10 Foundation, Inc.
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)
15 any later version.
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)
29 #include <stdio.h>
30 #include <sys/types.h>
32 extern void *malloc (), *realloc ();
33 static void memory_error_and_abort ();
35 /* **************************************************************** */
36 /* */
37 /* Memory Allocation and Deallocation. */
38 /* */
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. */
44 void *
45 xmalloc (bytes)
46 int bytes;
48 void *temp = malloc (bytes);
50 if (!temp)
51 memory_error_and_abort ("xmalloc");
52 return (temp);
55 void *
56 xrealloc (pointer, bytes)
57 void *pointer;
58 int bytes;
60 void *temp;
62 if (!pointer)
63 temp = malloc (bytes);
64 else
65 temp = realloc (pointer, bytes);
67 if (!temp)
68 memory_error_and_abort ("xrealloc");
70 return (temp);
73 static void
74 memory_error_and_abort (fname)
75 char *fname;
77 fprintf (stderr, "%s: Out of virtual memory!\n", fname);
78 abort ();
80 #endif /* !ALREADY_HAVE_XMALLOC */