sbrk.c 755 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <unistd.h>
  7. #include <errno.h>
  8. /* Defined in brk.c. */
  9. extern void *__curbrk attribute_hidden;
  10. /* Extend the process's data space by INCREMENT.
  11. If INCREMENT is negative, shrink data space by - INCREMENT.
  12. Return start of new space allocated, or -1 for errors. */
  13. void * sbrk (intptr_t increment)
  14. {
  15. void *oldbrk;
  16. if (__curbrk == NULL)
  17. if (brk (NULL) < 0) /* Initialize the break. */
  18. return (void *) -1;
  19. if (increment == 0)
  20. return __curbrk;
  21. oldbrk = __curbrk;
  22. if (brk (oldbrk + increment) < 0)
  23. return (void *) -1;
  24. return oldbrk;
  25. }
  26. libc_hidden_def(sbrk)