X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Futil%2Futil.h;h=39966d0b7b0a2586b7ce8d857871c5379d4ecb31;hp=30b472d47b6139c55d9b471d0e68a39fde076b20;hb=3daa33e027e327e75835ed5570bab150cb5e7a10;hpb=dd8fe077022138d1f6aca7e6d6cceec61f56ce95 diff --git a/lib/util/util.h b/lib/util/util.h index 30b472d..39966d0 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -18,6 +18,8 @@ #ifndef UTIL_H #define UTIL_H +#include + #ifndef container_of #define container_of(_ptr, _type, _member) ({ \ const typeof( ((_type *)0)->_member ) *__mptr = (_ptr); \ @@ -30,5 +32,24 @@ #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; \ + }) + +#define build_assert(x) \ + do { (void)sizeof(char[(x)?1:-1]); } while (0) + +void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen); + #endif /* UTIL_H */