From c49d626ed36f0af1f2ffe970c24b5177d9e9b197 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 18 May 2014 05:22:13 +0200 Subject: style + 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 | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/libmdsserver/macros.h') diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h index d70afc9..1623950 100644 --- a/src/libmdsserver/macros.h +++ b/src/libmdsserver/macros.h @@ -276,7 +276,7 @@ * * @param var The variable to which to assign the allocation * @param elements The number of elements to allocate - * @parma type The data type of the elements for which to create an allocation + * @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 xmalloc(var, elements, type) \ @@ -288,12 +288,29 @@ * * @param var The variable to which to assign the allocation * @param elements The number of elements to allocate - * @parma type The data type of the elements for which to create an allocation + * @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 xcalloc(var, elements, type) \ ((var = calloc(elements, sizeof(type))) == NULL) +/** + * Go to the label `pfail` if a condition is met + * + * @param CONDITION The condition + */ +#define fail_if(CONDITION) if (CONDITION) goto pfail + + +/** + * Run a set of instructions and return 1 if a condition is met + * + * @param CONDITION The condition + * @param INSTRUCTIONS The instruction (semicolon-terminated) + */ +#define exit_if(CONDITION, INSTRUCTIONS) if (CONDITION) { INSTRUCTIONS return 1; } + + #endif -- cgit v1.2.3-70-g09d2