home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / CLISP / CLISPSRC.TAR / clisp-1995-01-01 / src / readline / xmalloc.c < prev   
Encoding:
C/C++ Source or Header  |  1993-03-16  |  1.7 KB  |  67 lines

  1. /* xmalloc.c -- changed by Bruno Haible, 16 March 1993 */
  2.  
  3. /* Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Readline, a library for reading lines
  6.    of text with interactive input and history editing.
  7.  
  8.    Readline 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 of the License, or
  11.    (at your option) any later version.
  12.  
  13.    Readline 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.
  17.  
  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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "sysdep.h"
  23. #include <stdio.h>
  24.  
  25. /* **************************************************************** */
  26. /*                                    */
  27. /*            xmalloc and xrealloc ()                     */
  28. /*                                    */
  29. /* **************************************************************** */
  30.  
  31. static void memory_error_and_abort RL((void));
  32.  
  33. char *
  34. xmalloc (bytes)
  35.      int bytes;
  36. {
  37.   char *temp = (char *)malloc (bytes);
  38.  
  39.   if (!temp)
  40.     memory_error_and_abort ();
  41.   return (temp);
  42. }
  43.  
  44. char *
  45. xrealloc (pointer, bytes)
  46.      char *pointer;
  47.      int bytes;
  48. {
  49.   char *temp;
  50.  
  51.   if (!pointer)
  52.     temp = (char *)malloc (bytes);
  53.   else
  54.     temp = (char *)realloc (pointer, bytes);
  55.  
  56.   if (!temp)
  57.     memory_error_and_abort ();
  58.   return (temp);
  59. }
  60.  
  61. static void
  62. memory_error_and_abort ()
  63. {
  64.   fprintf (stderr, "readline: Out of virtual memory!\n");
  65.   abort ();
  66. }
  67.