fix brk/sbrk behavior to match the real legacy functions

This commit is contained in:
Rich Felker 2011-05-22 12:34:33 -04:00
parent c5025bfabe
commit 19892bf0a7
2 changed files with 4 additions and 2 deletions

View File

@ -2,5 +2,5 @@
int brk(void *end)
{
return -(syscall(SYS_brk, end) == -1);
return -(syscall(SYS_brk, end) != (unsigned long)end);
}

View File

@ -3,5 +3,7 @@
void *sbrk(ptrdiff_t inc)
{
return (void *)syscall(SYS_brk, syscall(SYS_brk, 0)+inc);
unsigned long cur = syscall(SYS_brk, 0);
if (inc && syscall(SYS_brk, cur+inc) != cur+inc) return (void *)-1;
return (void *)cur;
}