/*
 * brk.c
 */


#include<sys/types.h>
#include<sys/stat.h>

#include<callgate.h>
#include<sys/system.h>
#include<errno.h>
#include<string.h>
#include<signal.h>
#include<stdio.h>
#include<stropts.h>
#include<unistd.h>


extern int _brk(uint);


int brk(void *end_segment)
{
	static uint allocLast=0;
	uint alloc_last;


	alloc_last=ROUNDUP((uint)end_segment,PAGE_SIZE);
	if ((alloc_last-1) > allocLast)
	{
		if (_brk(alloc_last) != 0)return -1;
		allocLast = alloc_last;
	}

	return 0;
}
