[PATCH 1/6] Add CountBits() to the server.

Peter Hutterer peter.hutterer at who-t.net
Tue Oct 19 16:44:09 PDT 2010


From: Chase Douglas <chase.douglas at canonical.com>

Function to count the number of bits set in the given array.

Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
---
 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



More information about the xorg-devel mailing list