sbrk.c 814 B

123456789101112131415161718192021222324252627282930313233343536
  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. /* libc_hidden_proto(brk) */
  9. /* Defined in brk.c. */
  10. extern void *__curbrk attribute_hidden;
  11. /* Extend the process's data space by INCREMENT.
  12. If INCREMENT is negative, shrink data space by - INCREMENT.
  13. Return start of new space allocated, or -1 for errors. */
  14. /* libc_hidden_proto(sbrk) */
  15. void * sbrk (intptr_t increment)
  16. {
  17. void *oldbrk;
  18. if (__curbrk == NULL)
  19. if (brk (NULL) < 0) /* Initialize the break. */
  20. return (void *) -1;
  21. if (increment == 0)
  22. return __curbrk;
  23. oldbrk = __curbrk;
  24. if (brk (oldbrk + increment) < 0)
  25. return (void *) -1;
  26. return oldbrk;
  27. }
  28. libc_hidden_def(sbrk)