home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / indent-1.9.1-base.tgz / indent-1.9.1-base.tar / fsf / indent / globs.c < prev    next >
C/C++ Source or Header  |  1994-01-29  |  2KB  |  58 lines

  1. /* Copyright (c) 1993,1994, Joseph Arceneaux.  All rights reserved.
  2.  
  3.    Copyright (C) 1986, 1989, 1992 Free Software Foundation, Inc. All rights
  4.    reserved.
  5.  
  6.    This file is subject to the terms of the GNU General Public License as
  7.    published by the Free Software Foundation.  A copy of this license is
  8.    included with this software distribution in the file COPYING.  If you
  9.    do not have a copy, you may obtain a copy by writing to the Free
  10.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  11.  
  12.    This software is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details. */
  16.  
  17.  
  18. #include "sys.h"
  19.  
  20. /* Like malloc but get error if no storage available.  size really should be
  21.    size_t, but not all systems have size_t, so I hope "unsigned" will work.
  22.    It works for GNU style machines, where it is 32 bits, and works on
  23.    MS-DOS.  */
  24.  
  25. char *
  26. xmalloc (size)
  27.      unsigned size;
  28. {
  29.   register char *val = (char *) malloc (size);
  30.   if (!val)
  31.     {
  32.       fprintf (stderr, "indent: Virtual memory exhausted.\n");
  33.       exit (1);
  34.     }
  35. #if defined (DEBUG)
  36.   /* Fill it with garbage to detect code which depends on stuff being
  37.      zero-filled.  */
  38.   memset (val, 'x', size);
  39. #endif
  40.   return val;
  41. }
  42.  
  43. /* Like realloc but get error if no storage available.  */
  44.  
  45. char *
  46. xrealloc (ptr, size)
  47.      char *ptr;
  48.      unsigned size;
  49. {
  50.   register char *val = (char *) realloc (ptr, size);
  51.   if (!val)
  52.     {
  53.       fprintf (stderr, "indent: Virtual memory exhausted.\n");
  54.       exit (1);
  55.     }
  56.   return val;
  57. }
  58.