🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.misc.discuss
Article #1402

Re: alloca (was: makefile for gnu make on SGI)

#1402
From: David B.Anderson
Date: Thu, 17 Dec 1992 17:23
34 lines
1462 bytes
In article <19921217111545SEB1525@MVS.draper.com> SEB1525@MVS.draper.com (Steve Bacher) writes:
>In article <tmi3iac@sgi.sgi.com>,
>davea@quasar.mti.sgi.com (David B.Anderson) writes:
[ ]
>>Brendan is quite right.  And it _is_ probably simplest to use gcc alloca.c
[ ]
>I weighed grabbing alloca.c out of the gcc or emacs distribution.  But
>this alloca requires a function xmalloc() to be defined.  Why not just
[ ]
>Do you have to change xmalloc to malloc, or define xmalloc to be
>malloc in the compile?

This question has arisen several times in the last year because the
source to alloca.c does not describe xmalloc.  xmalloc is simply a malloc
wrapper that guarantees it will never return 0.

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
void *xmalloc(unsigned size)
{
  void *val;

  val = malloc(size);
  if(val == 0) {
    fprintf(stderr, "Oops! malloc on %lu bytes returned 0.\n", 
	(unsigned long)size);
    exit(EXIT_FAILURE);
  }
  return val;
}

Regards,
[ David B. Anderson             (415)390-4263             davea@sgi.com ]
Technical Details
Message-ID: <tnfoib0@sgi.sgi.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!sgigate!sgi!quasar.mti.sgi.com!davea

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!sgigate!sgi!quasar.mti.sgi.com!davea
From: davea@quasar.mti.sgi.com (David B.Anderson)
Newsgroups: gnu.misc.discuss
Subject: Re: alloca (was: makefile for gnu make on SGI)
Message-ID: <tnfoib0@sgi.sgi.com>
Date: 17 Dec 92 17:23:47 GMT
Sender: davea@quasar.mti.sgi.com
Organization: Silicon Graphics, Inc.  Mountain View, CA
Lines: 34