summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2008-04-11 11:29:23 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2008-04-11 11:29:23 +0200
commitd4691ada06fa89764570d6d57cae8cca6a93620f (patch)
treee04268cc87ebf7469b6f63f611b6b1199ce37f17 /src
parent12da0317f4046ed9425571d9752080d7f62d1f6e (diff)
Add td_min(), td_max() functions
Diffstat (limited to 'src')
-rw-r--r--src/common.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/common.h b/src/common.h
index a72f0b8..8b5b6dc 100644
--- a/src/common.h
+++ b/src/common.h
@@ -417,5 +417,21 @@ int strncasecmp(const char * s1, const char * s2, size_t len);
#endif
void create_dir(const char *dir_name, const unsigned int is_dir_name);
unsigned int filename_convert(char *dst, const char*src, const unsigned int n);
-
+/*
+ * td_min()/td_max() macros that also do
+ * strict type-checking.. See the
+ * "unnecessary" pointer comparison.
+ * Comes from Linux kernel
+ */
+#define td_min(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x < _y ? _x : _y; })
+
+#define td_max(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x > _y ? _x : _y; })
#endif