fix brk/sbrk behavior to match the real legacy functions
authorRich Felker <dalias@aerifal.cx>
Sun, 22 May 2011 16:34:33 +0000 (12:34 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 22 May 2011 16:34:33 +0000 (12:34 -0400)
src/linux/brk.c
src/linux/sbrk.c

index 9f63c5a8a39d88d28b89fcf4b29cfb9f7377049d..d91ee5a9b16b09c12c5ad1220e280c48888c3dd9 100644 (file)
@@ -2,5 +2,5 @@
 
 int brk(void *end)
 {
-       return -(syscall(SYS_brk, end) == -1);
+       return -(syscall(SYS_brk, end) != (unsigned long)end);
 }
index b2943a9239533967b1f8468dc607804b31335b0d..5fab74be29c83d729c5718d13f5106a1cd9be41d 100644 (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;
 }