]> mj.ucw.cz Git - libucw.git/commitdiff
Added a couple of useful macros: MIN, MAX, CLAMP, ARRAY_SIZE.
authorMartin Mares <mj@ucw.cz>
Wed, 7 Mar 2001 13:34:58 +0000 (13:34 +0000)
committerMartin Mares <mj@ucw.cz>
Wed, 7 Mar 2001 13:34:58 +0000 (13:34 +0000)
Removed NULL as it's already defined in config.h.

lib/lib.h

index 9283e7aadb896473b5b6143fd726225ee2eb2b1c..eb079dcd6fe94139b24643c856a1dc7e21256d8e 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
 
 #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"