home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1986, 1989 Free Software Foundation, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley, the University of Illinois,
- * Urbana, and Sun Microsystems, Inc. The name of either University
- * or Sun Microsystems may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
- #include <stdlib.h>
-
- #include "externs.h"
-
- #ifdef MEMDEBUG
- #undef xmalloc
- #undef xrealloc
- #endif
-
- #include "globs.h"
-
- /* Like malloc but get error if no storage available. */
-
- #ifdef MEMDEBUG
-
- /* Use the Mnemosyne.h debugging package instead,
- which reports leakages with source line numbers.
- (So you don't want the source line number to
- always say 'globs.c, line 35 :-) ) */
- char *
- xmalloc (size_t size) /* Dummies to keep the linker happy! */
- {
- fprintf(stderr, "Ahem - recompile *everything* with -DMEMDEBUG please!\n");
- exit(0);
- return(NULL);
- }
- char *
- xrealloc (void *xptr, size_t size)
- {
- fprintf(stderr, "Ahem - recompile *everything* with -DMEMDEBUG please!\n");
- exit(0);
- return(NULL);
- }
- #else
- char *
- xmalloc (size_t size)
- {
- size_t i;
- register char *val = (char *) malloc ((size_t)size);
- /* The author was assuming that malloc returned zeroed memory.
- This is not the case. Either use calloc (non-portable) or
- wipe it down yourself. [do it the hard way -- bzero isn't
- portable either...]*/
- if (!val)
- {
- fprintf (stderr,"indent: Virtual memory exhausted.\n");
- exit (1);
- }
- for (i = 0; i < size; i++) val[i] = '\0';
- return val;
- }
-
- /* Like realloc but get error if no storage available. */
-
- char *
- xrealloc (void *xptr, size_t size)
- {
- char *ptr = (char *)xptr;
- register char *val = (char *) realloc (ptr, (size_t)size);
- if (!val)
- {
- fprintf (stderr,"indent: Virtual memory exhausted.\n");
- exit (1);
- }
- return val;
- }
-
- #endif /* MEMDEBUG */
-
- /* Some systems lack memcpy so this does the same thing.
- If your system-supplied memcpy is more efficient, you might want
- to put "#define mymemcpy memcpy" in extern.h.
-
- Copy LEN bytes starting at SRCADDR to DESTADDR. Result undefined
- if the source overlaps with the destination. */
- char *
- mymemcpy (void *xdestaddr, void *xsrcaddr, int len)
- {
- register char *destaddr = (char *) xdestaddr;
- register char *srcaddr = (char *) xsrcaddr;
- for (; len; len--)
- *destaddr++ = *srcaddr++;
- return destaddr;
- }
-