ack/plat/linux386/libsys/sbrk.c
dtrg a0c67da261 Changed to actually work. (On modern Linux systems the old version just
crashes. On old Linux systems it apparently only worked by accident.)
2010-08-06 17:06:31 +00:00

36 lines
562 B
C

/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <unistd.h>
#include "libsys.h"
#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */
static char* current = NULL;
void* sbrk(intptr_t increment)
{
char* old;
char* new;
char* actual;
if (!current)
current = (char*) _syscall(__NR_brk, 0, 0, 0);
if (increment == 0)
return current;
old = current;
new = old + increment;
actual = (char*) _syscall(__NR_brk, (quad) new, 0, 0);
if (actual < new)
return OUT_OF_MEMORY;
current = actual;
return old;
}