morecore.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright (C) 1991-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _MALLOC_INTERNAL
  15. # define _MALLOC_INTERNAL
  16. # include <malloc.h>
  17. #endif
  18. #ifndef __GNU_LIBRARY__
  19. # define __sbrk sbrk
  20. #endif
  21. #ifdef __GNU_LIBRARY__
  22. /* It is best not to declare this and cast its result on foreign operating
  23. systems with potentially hostile include files. */
  24. # include <stddef.h>
  25. # include <stdlib.h>
  26. extern void *__sbrk (ptrdiff_t increment) __THROW;
  27. libc_hidden_proto (__sbrk)
  28. #endif
  29. #ifndef NULL
  30. # define NULL 0
  31. #endif
  32. /* Allocate INCREMENT more bytes of data space,
  33. and return the start of data space, or NULL on errors.
  34. If INCREMENT is negative, shrink data space. */
  35. void *
  36. __default_morecore (ptrdiff_t increment)
  37. {
  38. void *result = (void *) __sbrk (increment);
  39. if (result == (void *) -1)
  40. return NULL;
  41. return result;
  42. }
  43. libc_hidden_def (__default_morecore)