Add CountBits() to the server.
Function to count the number of bits set in the given array. Signed-off-by: Chase Douglas <chase.douglas@canonical.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
This commit is contained in:
parent
eaf0b6a4d8
commit
fc48a8f9f5
|
@ -418,3 +418,16 @@ FreeInputAttributes(InputAttributes *attrs)
|
||||||
free(attrs);
|
free(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
CountBits(const uint8_t *mask, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
if (BitIsOn(mask, i))
|
||||||
|
ret++;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ SOFTWARE.
|
||||||
#define BitIsOn(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
|
#define BitIsOn(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
|
||||||
#define SetBit(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] |= (1 << ((bit) & 7)))
|
#define SetBit(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] |= (1 << ((bit) & 7)))
|
||||||
#define ClearBit(ptr, bit) (((BYTE *)(ptr))[(bit)>>3] &= ~(1 << ((bit) & 7)))
|
#define ClearBit(ptr, bit) (((BYTE *)(ptr))[(bit)>>3] &= ~(1 << ((bit) & 7)))
|
||||||
|
extern _X_EXPORT int CountBits(const uint8_t *mask, int len);
|
||||||
|
|
||||||
#define SameClient(obj,client) \
|
#define SameClient(obj,client) \
|
||||||
(CLIENT_BITS((obj)->resource) == (client)->clientAsMask)
|
(CLIENT_BITS((obj)->resource) == (client)->clientAsMask)
|
||||||
|
|
Loading…
Reference in New Issue