brk.c 632 B

1234567891011121314151617181920212223242526272829303132
  1. /* From libc-5.3.12 */
  2. /*
  3. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include <errno.h>
  8. #include <unistd.h>
  9. #include <sys/syscall.h>
  10. libc_hidden_proto(brk)
  11. extern void * __curbrk;
  12. libc_hidden_proto(__curbrk)
  13. extern int __init_brk (void);
  14. libc_hidden_proto(__init_brk)
  15. extern void *_brk(void *ptr) attribute_hidden;
  16. int brk(void * end_data_seg)
  17. {
  18. if (__init_brk () == 0)
  19. {
  20. __curbrk = _brk(end_data_seg);
  21. if (__curbrk == end_data_seg)
  22. return 0;
  23. __set_errno(ENOMEM);
  24. }
  25. return -1;
  26. }
  27. libc_hidden_def(brk)