sbrk.c 444 B

12345678910111213141516171819202122232425262728293031
  1. /* $Source$
  2. * $State$
  3. * $Revision$
  4. */
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include "libsys.h"
  8. #define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */
  9. extern char _end[1];
  10. static char* current = _end;
  11. void* sbrk(intptr_t increment)
  12. {
  13. char* old;
  14. char* new;
  15. if (increment == 0)
  16. return current;
  17. old = current;
  18. new = old + increment;
  19. if (brk(new) < 0)
  20. return OUT_OF_MEMORY;
  21. current = new;
  22. return old;
  23. }