#include "util.h" /**AutomaticStart*************************************************************/ /*---------------------------------------------------------------------------*/ /* Static function prototypes */ /*---------------------------------------------------------------------------*/ /**AutomaticEnd***************************************************************/ /* * These are interface routines to be placed between a program and the * system memory allocator. * * It forces well-defined semantics for several 'borderline' cases: * * malloc() of a 0 size object is guaranteed to return something * which is not 0, and can safely be freed (but not dereferenced) * free() accepts (silently) an 0 pointer * realloc of a 0 pointer is allowed, and is equiv. to malloc() * */ char * MMalloc(size) long size; { char *p; if (size <= 0) { size = sizeof(long); } if ((p = (char *) malloc((unsigned) size)) == NIL(char)) { (void) fflush(stdout); (void) fprintf(stderr, "\nout of memory allocating %ld bytes\n", size); exit(1); } return p; } char * MMrealloc(obj, size) char *obj; long size; { char *p; if ( obj == NIL(char) ) { return MMalloc(size); } if (size <= 0) { size = sizeof(long); } if ( (p = (char *) realloc( obj, (unsigned) size ) ) == NIL(char) ) { (void) fflush(stdout); (void) fprintf(stderr, "\nout of memory re-allocating %ld bytes\n", size); exit(1); } return p; } void MMfree(obj) char *obj; { if (obj != 0) { free(obj); } }