home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume10 / parseargs / ckalloc.c < prev    next >
C/C++ Source or Header  |  1990-02-16  |  1KB  |  51 lines

  1. #include <useful.h>
  2. #include <funclist.h>
  3.  
  4. VERSIONID("$Header: ckalloc.c,v 2.0 89/12/24 00:56:21 eric Exp $");
  5.  
  6. /*
  7. **  CKALLOC -- allocate memory, checking for error conditions
  8. **
  9. **    If we cannot allocate memory, we call the list of functions
  10. **    in OutOfMemoryFuncs.  We then try again.  If the second attempt
  11. **    fails, we terminate the process.
  12. **
  13. **    Parameters:
  14. **        size -- the number of bytes of memory to be allocated.
  15. **
  16. **    Returns:
  17. **        A pointer to the allocated memory.
  18. **        Never returns if memory cannot be allocated.
  19. **
  20. **    Side Effects:
  21. **        As implied by memory allocation.
  22. **
  23. **    Globals:
  24. **        OutOfMemoryFuncs -- a FUNCLIST that is called when memory
  25. **            cannot be allocated.
  26. **
  27. **    Author:
  28. **        Eric Allman
  29. **        University of California, Berkeley
  30. */
  31.  
  32. FUNCLIST    *OutOfMemoryFuncs =    FUNCLISTNULL;
  33.  
  34. ARBPTR
  35. ckalloc(size)
  36.     unsigned int size;
  37. {
  38.     ARBPTR p;
  39.     extern char *malloc ARGS((unsigned int));
  40.  
  41.     p = __ malloc(size);
  42.     if (p == ARBNULL)
  43.     {
  44.         funclist_call(OutOfMemoryFuncs, ARBNULL);
  45.         p = __ malloc(size);
  46.         if (p == ARBNULL)
  47.             syserr("ckalloc: out of memory");
  48.     }
  49.     return (p);
  50. }
  51.