From 941d700796d2dbb65ace8c775b5f3be4f4677650 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 28 Jul 2014 05:39:10 +0200 Subject: reduce code complexity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/macros.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/libmdsserver') diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h index 59537ff..cbef69c 100644 --- a/src/libmdsserver/macros.h +++ b/src/libmdsserver/macros.h @@ -322,6 +322,20 @@ ((var = realloc(var, (elements) * sizeof(type))) == NULL) +/** + * Double to the size of an allocation on the heap + * + * @param old Variable in which to store the old value temporarily + * @param var The variable to which to assign the reallocation + * @param elements The number of elements to allocate + * @param type The data type of the elements for which to create an allocation + * @return :int Evaluates to true if an only if the allocation failed + */ +#define growalloc(old, var, elements, type) \ + (old = var, xrealloc(var, (elements) <<= 1, type) ? (var = old, (elements) >>= 1, perror(*argv), 1) : 0) + + + /** * Go to the label `pfail` if a condition is met * -- cgit v1.2.3-70-g09d2