sbrk.c 496 B

123456789101112131415161718192021222324252627
  1. /* From libc-5.3.12 */
  2. #include <errno.h>
  3. #include <unistd.h>
  4. #include <sys/syscall.h>
  5. libc_hidden_proto(sbrk)
  6. extern void * ___brk_addr;
  7. extern int __init_brk (void);
  8. extern void *_brk(void *ptr);
  9. void *
  10. sbrk(intptr_t increment)
  11. {
  12. if (__init_brk () == 0)
  13. {
  14. char * tmp = (char*)___brk_addr+increment;
  15. ___brk_addr = _brk(tmp);
  16. if (___brk_addr == tmp)
  17. return tmp-increment;
  18. __set_errno(ENOMEM);
  19. return ((void *) -1);
  20. }
  21. return ((void *) -1);
  22. }
  23. libc_hidden_def(sbrk)