home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD2.img / d4xx / d473 / cnewssrc / cnews_src.lzh / libc / emalloc.c < prev    next >
C/C++ Source or Header  |  1990-05-30  |  442b  |  28 lines

  1. /*
  2.  * emalloc - malloc with error() called when out of space
  3.  */
  4.  
  5. #include <stdio.h>
  6. #ifdef unix
  7. # include <sys/types.h>
  8. #endif /* unix */
  9. #include "libc.h"
  10.  
  11. extern void error();
  12.  
  13. char *
  14. emalloc(amount)
  15. unsigned amount;
  16. {
  17.     register char *it;
  18.  
  19.     it = malloc(amount);
  20.     if (it == NULL) {
  21.         static char camount[25];        /* Enough to sprintf an unsigned. */
  22.  
  23.         sprintf(camount, "%u", amount);
  24.         error("malloc(%s) failed", camount);
  25.     }    
  26.     return(it);
  27. }
  28.