sbrk.c 450 B

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