summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-10-21 12:15:20 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-11-13 17:20:59 +0800
commite160c3eba138d22b25b95df46fdc0e7b9865d902 (patch)
treec8dfc1f4d50782ac7cc2b943343e228ade86f4ab /lib
parentdd8fe077022138d1f6aca7e6d6cceec61f56ce95 (diff)
downloadtalos-petitboot-e160c3eba138d22b25b95df46fdc0e7b9865d902.tar.gz
talos-petitboot-e160c3eba138d22b25b95df46fdc0e7b9865d902.zip
lib/util: Implement min & max macros
Standard type-safe min & max implementations. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/util/util.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/util/util.h b/lib/util/util.h
index 30b472d..8c08dc5 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -30,5 +30,19 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#define min(a,b) ({ \
+ typeof(a) _min_a = (a); \
+ typeof(b) _min_b = (b); \
+ (void)(&_min_a == &_min_b); \
+ _min_a < _min_b ? _min_a : _min_b; \
+ })
+
+#define max(a,b) ({ \
+ typeof(a) _max_a = (a); \
+ typeof(b) _max_b = (b); \
+ (void)(&_max_a == &_max_b); \
+ _max_a > _max_b ? _max_a : _max_b; \
+ })
+
#endif /* UTIL_H */
OpenPOWER on IntegriCloud