home *** CD-ROM | disk | FTP | other *** search
- #include <useful.h>
- #include <funclist.h>
-
- VERSIONID("$Header: ckalloc.c,v 2.0 89/12/24 00:56:21 eric Exp $");
-
- /*
- ** CKALLOC -- allocate memory, checking for error conditions
- **
- ** If we cannot allocate memory, we call the list of functions
- ** in OutOfMemoryFuncs. We then try again. If the second attempt
- ** fails, we terminate the process.
- **
- ** Parameters:
- ** size -- the number of bytes of memory to be allocated.
- **
- ** Returns:
- ** A pointer to the allocated memory.
- ** Never returns if memory cannot be allocated.
- **
- ** Side Effects:
- ** As implied by memory allocation.
- **
- ** Globals:
- ** OutOfMemoryFuncs -- a FUNCLIST that is called when memory
- ** cannot be allocated.
- **
- ** Author:
- ** Eric Allman
- ** University of California, Berkeley
- */
-
- FUNCLIST *OutOfMemoryFuncs = FUNCLISTNULL;
-
- ARBPTR
- ckalloc(size)
- unsigned int size;
- {
- ARBPTR p;
- extern char *malloc ARGS((unsigned int));
-
- p = __ malloc(size);
- if (p == ARBNULL)
- {
- funclist_call(OutOfMemoryFuncs, ARBNULL);
- p = __ malloc(size);
- if (p == ARBNULL)
- syserr("ckalloc: out of memory");
- }
- return (p);
- }
-