2
0

brk.c 648 B

1234567891011121314151617181920212223242526
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "test_helpers.h"
  5. int main(void) {
  6. // sbrk report current brk
  7. void * current = sbrk(0);
  8. ERROR_IF(sbrk, current, == (void *)-1);
  9. // sbrk increment and report previous brk
  10. void * prev = current;
  11. current = sbrk(4096);
  12. ERROR_IF(sbrk, current, != prev);
  13. // sbrk report current break
  14. prev = current;
  15. current = sbrk(0);
  16. ERROR_IF(sbrk, current, != (void*)((uintptr_t)prev + 4096));
  17. // brk set break to new value
  18. int status = brk((void*)((uintptr_t)current + 4096));
  19. ERROR_IF(brk, status, == -1);
  20. UNEXP_IF(brk, status, != 0);
  21. }