summaryrefslogtreecommitdiff
path: root/include/alloca.h
diff options
context:
space:
mode:
authorPeter S. Mazinger <ps.m@gmx.net>2009-10-17 01:14:16 +0200
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2009-11-19 22:37:08 +0100
commit0ccab5e4a96ae1ad60a815c0045e1f0a51ea27d1 (patch)
tree09c38c588e31afd8f1ca49f9175537f07d264391 /include/alloca.h
parentbe800f25ee834eea10fbc4d2bfe623d0855753e3 (diff)
move extend_alloca macro to alloca.h
guard it by _LIBC. __MAX_ALLOCA_CUTOFF is not needed on target either Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'include/alloca.h')
-rw-r--r--include/alloca.h33
1 files changed, 32 insertions, 1 deletions
diff --git a/include/alloca.h b/include/alloca.h
index b4fc31738..2565b4835 100644
--- a/include/alloca.h
+++ b/include/alloca.h
@@ -36,7 +36,38 @@ extern void *alloca (size_t __size) __THROW;
# define alloca(size) __builtin_alloca (size)
#endif /* GCC. */
-#define __MAX_ALLOCA_CUTOFF 65536
+#ifdef _LIBC
+# define __MAX_ALLOCA_CUTOFF 65536
+
+# include <bits/stackinfo.h>
+# ifdef _STACK_GROWS_DOWN
+# define extend_alloca(buf, len, newlen) \
+ (__typeof (buf)) ({ size_t __newlen = (newlen); \
+ char *__newbuf = alloca (__newlen); \
+ if (__newbuf + __newlen == (char *) buf) \
+ len += __newlen; \
+ else \
+ len = __newlen; \
+ __newbuf; })
+# elif defined _STACK_GROWS_UP
+# define extend_alloca(buf, len, newlen) \
+ (__typeof (buf)) ({ size_t __newlen = (newlen); \
+ char *__newbuf = alloca (__newlen); \
+ char *__buf = (buf); \
+ if (__buf + __newlen == __newbuf) \
+ { \
+ len += __newlen; \
+ __newbuf = __buf; \
+ } \
+ else \
+ len = __newlen; \
+ __newbuf; })
+# else
+# error unknown stack
+# define extend_alloca(buf, len, newlen) \
+ alloca (((len) = (newlen)))
+# endif
+#endif
__END_DECLS