sbrk.c 812 B

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