home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / gnu / misc / discuss / 4033 < prev    next >
Encoding:
Text File  |  1992-12-17  |  1.4 KB  |  45 lines

  1. Path: sparky!uunet!olivea!sgigate!sgi!quasar.mti.sgi.com!davea
  2. From: davea@quasar.mti.sgi.com (David B.Anderson)
  3. Newsgroups: gnu.misc.discuss
  4. Subject: Re: alloca (was: makefile for gnu make on SGI)
  5. Message-ID: <tnfoib0@sgi.sgi.com>
  6. Date: 17 Dec 92 17:23:47 GMT
  7. Sender: davea@quasar.mti.sgi.com
  8. Organization: Silicon Graphics, Inc.  Mountain View, CA
  9. Lines: 34
  10.  
  11. In article <19921217111545SEB1525@MVS.draper.com> SEB1525@MVS.draper.com (Steve Bacher) writes:
  12. >In article <tmi3iac@sgi.sgi.com>,
  13. >davea@quasar.mti.sgi.com (David B.Anderson) writes:
  14. [ ]
  15. >>Brendan is quite right.  And it _is_ probably simplest to use gcc alloca.c
  16. [ ]
  17. >I weighed grabbing alloca.c out of the gcc or emacs distribution.  But
  18. >this alloca requires a function xmalloc() to be defined.  Why not just
  19. [ ]
  20. >Do you have to change xmalloc to malloc, or define xmalloc to be
  21. >malloc in the compile?
  22.  
  23. This question has arisen several times in the last year because the
  24. source to alloca.c does not describe xmalloc.  xmalloc is simply a malloc
  25. wrapper that guarantees it will never return 0.
  26.  
  27. #include <stdio.h>
  28. #include <malloc.h>
  29. #include <stdlib.h>
  30. void *xmalloc(unsigned size)
  31. {
  32.   void *val;
  33.  
  34.   val = malloc(size);
  35.   if(val == 0) {
  36.     fprintf(stderr, "Oops! malloc on %lu bytes returned 0.\n", 
  37.     (unsigned long)size);
  38.     exit(EXIT_FAILURE);
  39.   }
  40.   return val;
  41. }
  42.  
  43. Regards,
  44. [ David B. Anderson             (415)390-4263             davea@sgi.com ]
  45.