brk.c 604 B

12345678910111213141516171819202122232425262728293031
  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. extern int __init_brk (void);
  13. libc_hidden_proto(__init_brk)
  14. extern void *_brk(void *ptr) attribute_hidden;
  15. int brk(void * end_data_seg)
  16. {
  17. if (__init_brk () == 0)
  18. {
  19. __curbrk = _brk(end_data_seg);
  20. if (__curbrk == end_data_seg)
  21. return 0;
  22. __set_errno(ENOMEM);
  23. }
  24. return -1;
  25. }
  26. libc_hidden_def(brk)