home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / indent / globs.c < prev    next >
C/C++ Source or Header  |  1999-06-10  |  2KB  |  58 lines

  1. /* Copyright (C) 1986, 1989, 1992 Free Software Foundation, Inc. All rights
  2.    reserved.
  3.  
  4.    Redistribution and use in source and binary forms are permitted
  5.    provided that the above copyright notice and this paragraph are
  6.    duplicated in all such forms and that any documentation, advertising
  7.    materials, and other materials related to such distribution and use
  8.    acknowledge that the software was developed by the University of
  9.    California, Berkeley, the University of Illinois, Urbana, and Sun
  10.    Microsystems, Inc.  The name of either University or Sun Microsystems
  11.    may not be used to endorse or promote products derived from this
  12.    software without specific prior written permission. THIS SOFTWARE IS
  13.    PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  14.    INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  15.    MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
  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.