From: Chase Douglas <[email protected]> Function to count the number of bits set in the given array.
Signed-off-by: Chase Douglas <[email protected]> Signed-off-by: Peter Hutterer <[email protected]> Reviewed-by: Chase Douglas <[email protected]> --- dix/inpututils.c | 13 +++++++++++++ include/inputstr.h | 1 + 2 files changed, 14 insertions(+), 0 deletions(-) diff --git a/dix/inpututils.c b/dix/inpututils.c index 6693c67..9738033 100644 --- a/dix/inpututils.c +++ b/dix/inpututils.c @@ -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; +} diff --git a/include/inputstr.h b/include/inputstr.h index 1b504e9..ec9749e 100644 --- a/include/inputstr.h +++ b/include/inputstr.h @@ -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) -- 1.7.2.3 _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
