* Sync comment with code's reality.
[dragonfly.git] / contrib / texinfo / lib / xmalloc.c
1 /* xmalloc.c -- safe versions of malloc and realloc */
2
3 /* This file is part of GNU Info, a program for reading online documentation
4    stored in Info format.
5
6    This file has appeared in prior works by the Free Software Foundation;
7    thus it carries copyright dates from 1988 through 1993.
8
9    Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993 Free Software
10    Foundation, Inc.
11
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.
16
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.
21
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.
25
26    Written by Brian Fox (bfox@ai.mit.edu). */
27
28 #if !defined (ALREADY_HAVE_XMALLOC)
29 #include <stdio.h>
30 #include <sys/types.h>
31
32 extern void *malloc (), *realloc ();
33 static void memory_error_and_abort ();
34
35 /* **************************************************************** */
36 /*                                                                  */
37 /*                 Memory Allocation and Deallocation.              */
38 /*                                                                  */
39 /* **************************************************************** */
40
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;
47 {
48   void *temp = malloc (bytes);
49
50   if (!temp)
51     memory_error_and_abort ("xmalloc");
52   return (temp);
53 }
54
55 void *
56 xrealloc (pointer, bytes)
57      void *pointer;
58      int bytes;
59 {
60   void *temp;
61
62   if (!pointer)
63     temp = malloc (bytes);
64   else
65     temp = realloc (pointer, bytes);
66
67   if (!temp)
68     memory_error_and_abort ("xrealloc");
69
70   return (temp);
71 }
72
73 static void
74 memory_error_and_abort (fname)
75      char *fname;
76 {
77   fprintf (stderr, "%s: Out of virtual memory!\n", fname);
78   abort ();
79 }
80 #endif /* !ALREADY_HAVE_XMALLOC */