From df89ea2887ddbfc0d7eea40cb345f3b29027218f Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Mon, 23 Jun 2008 16:31:40 +0200 Subject: [PATCH] Add type and memset safe alloca wrapper. --- common/util.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/util.h b/common/util.h index 6e76a71e..f0caaa08 100644 --- a/common/util.h +++ b/common/util.h @@ -28,6 +28,7 @@ #include #include #include +#include /** A list of possible position, not sex related */ typedef enum @@ -60,6 +61,10 @@ typedef struct #define ssizeof(foo) (ssize_t)sizeof(foo) #define countof(foo) (ssizeof(foo) / ssizeof(foo[0])) +#define p_alloca(type, count) \ + ((type *)memset(alloca(sizeof(type) * (count)), \ + 0, sizeof(type) * (count))) + #define p_alloc_nr(x) (((x) + 16) * 3 / 2) #define p_new(type, count) ((type *)xmalloc(sizeof(type) * (count))) #define p_clear(p, count) ((void)memset((p), 0, sizeof(*(p)) * (count)))