brk.c 625 B

1234567891011121314151617181920212223242526272829303132
  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. libc_hidden_proto(brk)
  10. #define __NR___syscall_brk __NR_brk
  11. static inline _syscall1(void *, __syscall_brk, void *, end)
  12. /* This must be initialized data because commons can't have aliases. */
  13. void * __curbrk attribute_hidden = 0;
  14. int brk(void *addr)
  15. {
  16. void *newbrk = __syscall_brk(addr);
  17. __curbrk = newbrk;
  18. if (newbrk < addr) {
  19. __set_errno (ENOMEM);
  20. return -1;
  21. }
  22. return 0;
  23. }
  24. libc_hidden_def(brk)