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:
Chase Douglas 2010-10-19 13:37:38 +10:00 committed by Peter Hutterer
parent eaf0b6a4d8
commit fc48a8f9f5
2 changed files with 14 additions and 0 deletions

View File

@ -418,3 +418,16 @@ FreeInputAttributes(InputAttributes *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;
}

View File

@ -60,6 +60,7 @@ SOFTWARE.
#define BitIsOn(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)))
extern _X_EXPORT int CountBits(const uint8_t *mask, int len);
#define SameClient(obj,client) \
(CLIENT_BITS((obj)->resource) == (client)->clientAsMask)