ftp.nice.ch/pub/next/developer/languages/lisp/AKCL.1.599.s.tar.gz#/akcl-1-599/c/sbrkNeXT.c

This is sbrkNeXT.c in view mode; [Download] [Up]

/*
 *	sbrkNeXT.c: replacement for NeXT's bogus sbrk
 *
 *		by Noritake Yonezawa, July 28, 1991
 */
#include <c.h>
#include <mach.h>
#include <stdio.h>

char *mach_maplimit = 0;
char *mach_brkpt = 0;
int big_heap = 0x1000000;

char *
my_sbrk(incr)
     int incr;
{
  char *temp, *ptr;
  kern_return_t rtn;

  if (mach_brkpt == 0)
    {
      if ((rtn = vm_allocate(task_self(), (vm_address_t *)&mach_brkpt,
			     big_heap, TRUE)) != KERN_SUCCESS)
	{
	  mach_error("my_sbrk: vm_allocate failed", rtn);
	  return ((char *)-1);
	}
      mach_maplimit = mach_brkpt + big_heap;
    }
  if (incr == 0) {
    return (mach_brkpt);
  }
  else
    {
      ptr = mach_brkpt + incr;
      if (ptr <= mach_maplimit)
	{
	  temp = mach_brkpt;
	  mach_brkpt = ptr;
	  return (temp);
	}
      else
	{
	  fprintf (stderr, "my_sbrk: no more memory\n");
	  return ((char *)-1);
	}
    }
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.