From 948bf112e3b3aba44e2dabfd0fa47724097166d3 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 7 Mar 2001 13:34:58 +0000 Subject: [PATCH] Added a couple of useful macros: MIN, MAX, CLAMP, ARRAY_SIZE. Removed NULL as it's already defined in config.h. --- lib/lib.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/lib.h b/lib/lib.h index 9283e7aa..eb079dcd 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -19,16 +19,19 @@ #define _GNU_SOURCE -#ifndef NULL -#define NULL ((void *)0) -#endif - /* Ugly structure handling macros */ #define OFFSETOF(s, i) ((unsigned int)&((s *)0)->i) #define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) #define ALIGN(s, a) (((s)+a-1)&~(a-1)) +/* Some other macros */ + +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define CLAMP(x,min,max) ({ int _t=x; (_t < min) ? min : (_t > max) ? max : _t; }) +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a))) + /* Temporary Files */ #define TMP_DIR "tmp" -- 2.39.2