diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-10-21 12:15:20 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-11-13 17:20:59 +0800 |
commit | e160c3eba138d22b25b95df46fdc0e7b9865d902 (patch) | |
tree | c8dfc1f4d50782ac7cc2b943343e228ade86f4ab /lib/util/util.h | |
parent | dd8fe077022138d1f6aca7e6d6cceec61f56ce95 (diff) | |
download | petitboot-e160c3eba138d22b25b95df46fdc0e7b9865d902.zip petitboot-e160c3eba138d22b25b95df46fdc0e7b9865d902.tar.gz |
lib/util: Implement min & max macros
Standard type-safe min & max implementations.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib/util/util.h')
-rw-r--r-- | lib/util/util.h | 14 |
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 */ |