/* $Id: xmalloc.c,v 1.4 2002/03/02 20:35:52 sverrehu Exp $ */ /*------------------------------------------------------------------------ | FILE xmalloc.c | MODULE OF xalloc - memory allocation with error checking | | DESCRIPTION malloc-matching routine. Aborts program or calls a | user supplied function if no more memory left. | | WRITTEN BY Sverre H. Huseby +----------------------------------------------------------------------*/ #include #include "xalloc.h" extern void _xaOutOfMem(void); /*-----------------------------------------------------------------------+ | PUBLIC FUNCTIONS | +-----------------------------------------------------------------------*/ /*------------------------------------------------------------------------ | NAME xmalloc | | FUNCTION Do as malloc(3), but with error handling. | | SYNOPSIS #include "xalloc.h" | void *xmalloc(size_t size); | | INPUT size number of bytes to allocate. | | RETURNS Pointer to buffer allocated. Never returns in case | of error. */ void * xmalloc(size_t size) { void *ret; if ((ret = malloc(size)) == NULL) _xaOutOfMem(); return ret; }