2007-04-21 23:02:11 +00:00
|
|
|
/* $Source$
|
|
|
|
* $State$
|
|
|
|
* $Revision$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "libsys.h"
|
|
|
|
|
|
|
|
#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */
|
|
|
|
|
2010-08-06 17:06:31 +00:00
|
|
|
static char* current = NULL;
|
2007-04-21 23:02:11 +00:00
|
|
|
|
|
|
|
void* sbrk(intptr_t increment)
|
|
|
|
{
|
|
|
|
char* old;
|
|
|
|
char* new;
|
2010-08-06 17:06:31 +00:00
|
|
|
char* actual;
|
2007-04-21 23:02:11 +00:00
|
|
|
|
2010-08-06 17:06:31 +00:00
|
|
|
if (!current)
|
|
|
|
current = (char*) _syscall(__NR_brk, 0, 0, 0);
|
|
|
|
|
2007-04-21 23:02:11 +00:00
|
|
|
if (increment == 0)
|
|
|
|
return current;
|
|
|
|
|
|
|
|
old = current;
|
|
|
|
new = old + increment;
|
2010-08-06 17:06:31 +00:00
|
|
|
|
|
|
|
actual = (char*) _syscall(__NR_brk, (quad) new, 0, 0);
|
|
|
|
if (actual < new)
|
2007-04-21 23:02:11 +00:00
|
|
|
return OUT_OF_MEMORY;
|
|
|
|
|
2010-08-06 17:06:31 +00:00
|
|
|
current = actual;
|
2007-04-21 23:02:11 +00:00
|
|
|
return old;
|
|
|
|
}
|