alloca.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Copyright (C) 1992, 1996, 1997, 1998, 1999 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 _ALLOCA_H
  15. #define _ALLOCA_H 1
  16. #include <features.h>
  17. #define __need_size_t
  18. #include <stddef.h>
  19. __BEGIN_DECLS
  20. /* Remove any previous definitions. */
  21. #undef alloca
  22. /* Allocate a block that will be freed when the calling function exits. */
  23. extern void *alloca (size_t __size) __THROW;
  24. #ifdef __GNUC__
  25. # define alloca(size) __builtin_alloca (size)
  26. #endif /* GCC. */
  27. #ifdef _LIBC
  28. # define __MAX_ALLOCA_CUTOFF 65536
  29. # include <bits/stackinfo.h>
  30. # ifdef _STACK_GROWS_DOWN
  31. # define extend_alloca(buf, len, newlen) \
  32. (__typeof (buf)) ({ size_t __newlen = (newlen); \
  33. char *__newbuf = alloca (__newlen); \
  34. if (__newbuf + __newlen == (char *) buf) \
  35. len += __newlen; \
  36. else \
  37. len = __newlen; \
  38. __newbuf; })
  39. # elif defined _STACK_GROWS_UP
  40. # define extend_alloca(buf, len, newlen) \
  41. (__typeof (buf)) ({ size_t __newlen = (newlen); \
  42. char *__newbuf = alloca (__newlen); \
  43. char *__buf = (buf); \
  44. if (__buf + __newlen == __newbuf) \
  45. { \
  46. len += __newlen; \
  47. __newbuf = __buf; \
  48. } \
  49. else \
  50. len = __newlen; \
  51. __newbuf; })
  52. # else
  53. # error unknown stack
  54. # define extend_alloca(buf, len, newlen) \
  55. alloca (((len) = (newlen)))
  56. # endif
  57. extern int __libc_alloca_cutoff (size_t size);
  58. #endif
  59. __END_DECLS
  60. #endif /* alloca.h */