Commit 3c0bc273 authored by Bruno Randolf's avatar Bruno Randolf

util: Add TOGGLE_BITSET

From Tuomas pull request, but type cast added.
parent a29bf8e2
......@@ -122,6 +122,21 @@ kilo_mega_ize(unsigned int val);
#define TOGGLE_BIT(_x, _m) (_x) ^= (_m)
/**
* TOGGLE_BITSET() - toggle set of bits as a whole
* @_x: an integer variable
* @_s: an integer variable interpreted as a bitset
* @_t: type (e.g. u_int16_t)
* If any of the bits are set, all bits will be unset. Otherwise, if
* none of the bits are set, all bits will be set.
*/
#define TOGGLE_BITSET(_x, _s, _type) do { \
if ((_x) & (_s)) \
(_x) &= (_type)~(_s); \
else \
(_x) |= (_s); \
} while(0)
#define max(_x, _y) ((_x) > (_y) ? (_x) : (_y))
#define min(_x, _y) ((_x) < (_y) ? (_x) : (_y))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment