brk.c 610 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <errno.h>
  7. #include <unistd.h>
  8. #include <sys/syscall.h>
  9. #define __NR___syscall_brk __NR_brk
  10. static __always_inline _syscall1(void *, __syscall_brk, void *, end)
  11. /* This must be initialized data because commons can't have aliases. */
  12. void * __curbrk attribute_hidden = 0;
  13. int brk(void *addr)
  14. {
  15. void *newbrk = __syscall_brk(addr);
  16. __curbrk = newbrk;
  17. if (newbrk < addr) {
  18. __set_errno (ENOMEM);
  19. return -1;
  20. }
  21. return 0;
  22. }
  23. libc_hidden_def(brk)