Files
libstdwullie/src/memory/brk.c
T
2026-10-26 18:55:09 +00:00

38 lines
838 B
C

// this code is licenced under Wrathmark licence
// © 2026 wullie wulliestudio.com
// please see attached licence for full usage and rights
#include "stdWullie/memory/brk.h"
#include "stdWullie/exit.h"
#include "LocalHeader.h"
int brk(void *address){
long result = syscall1(SYS_brk, (long)address);
if((void*)result == address){
return 0;
}
return -1;
}
void *sbrk(intptr_t incrament){
// gets the last break point and checks whether we just wanted that or do something else
void *prevBrk = (void *)syscall1(SYS_brk, 0);
if(incrament == 0){
return prevBrk;
}
// something else
void *newBrk = (char *)prevBrk + incrament;
long result = syscall1(SYS_brk, (long)newBrk);
if((void *)result != newBrk){
safeError("FAULT IN ALLOCATING NEW BREAK");
}
// pointer to the start of the new memory
return prevBrk;
}