1 #ifndef __XEN_TOOLS_LIBS__ 2 #define __XEN_TOOLS_LIBS__ 3 4 #ifndef BUILD_BUG_ON 5 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 6 #define BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); }) 7 #else 8 #define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)])) 9 #endif 10 #endif 11 12 #ifndef ARRAY_SIZE 13 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a)) 14 #endif 15 16 #ifndef MAX 17 #define MAX(x, y) ((x) > (y) ? (x) : (y)) 18 #endif 19 20 #ifndef MIN 21 #define MIN(x, y) ((x) < (y) ? (x) : (y)) 22 #endif 23 24 #ifndef min 25 #define min(x, y) \ 26 ({ \ 27 const typeof(x) _x = (x); \ 28 const typeof(y) _y = (y); \ 29 (void) (&_x == &_y); \ 30 (_x < _y) ? _x : _y; \ 31 }) 32 #endif 33 34 #ifndef max 35 #define max(x, y) \ 36 ({ \ 37 const typeof(x) _x = (x); \ 38 const typeof(y) _y = (y); \ 39 (void)(&_x == &_y); \ 40 (_x > _y) ? _x : _y; \ 41 }) 42 #endif 43 44 #ifndef min_t 45 #define min_t(type, x, y) \ 46 ({ \ 47 const type _x = (x); \ 48 const type _y = (y); \ 49 (_x < _y) ? _x: _y; \ 50 }) 51 #endif 52 53 #ifndef max_t 54 #define max_t(type, x, y) \ 55 ({ \ 56 const type _x = (x); \ 57 const type _y = (y); \ 58 (_x > _y) ? _x: _y; \ 59 }) 60 #endif 61 62 #endif /* __XEN_TOOLS_LIBS__ */ 63