lib/util: Implement min & max macros
[petitboot] / lib / util / util.h
index 30b472d47b6139c55d9b471d0e68a39fde076b20..8c08dc52eafd7e812949c78fba01e7f8b051a674 100644 (file)
 
 #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 */