mirror of
https://github.com/SELinuxProject/selinux
synced 2025-01-13 08:50:53 +00:00
libsepol: Create function ebitmap_highest_set_bit()
Create the function ebitmap_highest_set_bit() which returns the position of the highest bit set in the ebitmap. The return value is valid only if the ebitmap is not empty. An empty ebitmap will return 0. Signed-off-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
parent
49ff851c98
commit
8f5409cf4c
@ -94,6 +94,7 @@ extern int ebitmap_contains(const ebitmap_t * e1, const ebitmap_t * e2);
|
||||
extern int ebitmap_match_any(const ebitmap_t *e1, const ebitmap_t *e2);
|
||||
extern int ebitmap_get_bit(const ebitmap_t * e, unsigned int bit);
|
||||
extern int ebitmap_set_bit(ebitmap_t * e, unsigned int bit, int value);
|
||||
extern unsigned int ebitmap_highest_set_bit(ebitmap_t * e);
|
||||
extern void ebitmap_destroy(ebitmap_t * e);
|
||||
extern int ebitmap_read(ebitmap_t * e, void *fp);
|
||||
|
||||
|
@ -344,6 +344,26 @@ int ebitmap_set_bit(ebitmap_t * e, unsigned int bit, int value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int ebitmap_highest_set_bit(ebitmap_t * e)
|
||||
{
|
||||
ebitmap_node_t *n;
|
||||
MAPTYPE map;
|
||||
unsigned int pos = 0;
|
||||
|
||||
n = e->node;
|
||||
if (!n)
|
||||
return 0;
|
||||
|
||||
while (n->next)
|
||||
n = n->next;
|
||||
|
||||
map = n->map;
|
||||
while (map >>= 1)
|
||||
pos++;
|
||||
|
||||
return n->startbit + pos;
|
||||
}
|
||||
|
||||
void ebitmap_destroy(ebitmap_t * e)
|
||||
{
|
||||
ebitmap_node_t *n, *temp;
|
||||
|
Loading…
Reference in New Issue
Block a user