home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / d / indent / !Indent / c / globs < prev    next >
Encoding:
Text File  |  1991-02-22  |  3.0 KB  |  102 lines

  1. /* Copyright (C) 1986, 1989 Free Software Foundation, Inc.
  2.  * All rights 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,
  7.  * advertising materials, and other materials related to such
  8.  * distribution and use acknowledge that the software was developed
  9.  * by the University of California, Berkeley, the University of Illinois,
  10.  * Urbana, and Sun Microsystems, Inc.  The name of either University
  11.  * or Sun Microsystems may not be used to endorse or promote products
  12.  * derived from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. #include <stdlib.h>
  19.  
  20. #include "externs.h"
  21.  
  22. #ifdef MEMDEBUG
  23. #undef xmalloc
  24. #undef xrealloc
  25. #endif
  26.  
  27. #include "globs.h"
  28.  
  29. /* Like malloc but get error if no storage available.  */
  30.  
  31. #ifdef MEMDEBUG
  32.  
  33.                      /* Use the Mnemosyne.h debugging package instead,
  34.                         which reports leakages with source line numbers.
  35.                         (So you don't want the source line number to
  36.                          always say 'globs.c, line 35 :-)    ) */
  37. char *
  38. xmalloc (size_t size)         /* Dummies to keep the linker happy! */
  39. {
  40.   fprintf(stderr, "Ahem - recompile *everything* with -DMEMDEBUG please!\n");
  41.   exit(0);
  42.   return(NULL);
  43. }
  44. char *
  45. xrealloc (void *xptr, size_t size)
  46. {
  47.   fprintf(stderr, "Ahem - recompile *everything* with -DMEMDEBUG please!\n");
  48.   exit(0);
  49.   return(NULL);
  50. }
  51. #else
  52. char *
  53. xmalloc (size_t size)
  54. {
  55.   size_t i;
  56.   register char *val = (char *) malloc ((size_t)size);
  57.   /* The author was assuming that malloc returned zeroed memory.
  58.      This is not the case. Either use calloc (non-portable) or
  59.      wipe it down yourself.  [do it the hard way -- bzero isn't
  60.      portable either...]*/
  61.   if (!val)
  62.     {
  63.       fprintf (stderr,"indent: Virtual memory exhausted.\n");
  64.       exit (1);
  65.     }
  66.   for (i = 0; i < size; i++) val[i] = '\0';
  67.   return val;
  68. }
  69.  
  70. /* Like realloc but get error if no storage available.  */
  71.  
  72. char *
  73. xrealloc (void *xptr, size_t size)
  74. {
  75. char *ptr = (char *)xptr;
  76.   register char *val = (char *) realloc (ptr, (size_t)size);
  77.   if (!val)
  78.     {
  79.       fprintf (stderr,"indent: Virtual memory exhausted.\n");
  80.       exit (1);
  81.     }
  82.   return val;
  83. }
  84.  
  85. #endif /* MEMDEBUG */
  86.  
  87. /* Some systems lack memcpy so this does the same thing.
  88.    If your system-supplied memcpy is more efficient, you might want
  89.    to put "#define mymemcpy memcpy" in extern.h.
  90.  
  91.    Copy LEN bytes starting at SRCADDR to DESTADDR.  Result undefined
  92.    if the source overlaps with the destination.  */
  93. char *
  94. mymemcpy (void *xdestaddr, void *xsrcaddr, int len)
  95. {
  96. register char *destaddr = (char *) xdestaddr;
  97. register char *srcaddr = (char *) xsrcaddr;
  98.   for (; len; len--)
  99.     *destaddr++ = *srcaddr++;
  100.   return destaddr;
  101. }
  102.