diff --git a/libsepol/include/sepol/policydb/ebitmap.h b/libsepol/include/sepol/policydb/ebitmap.h index 910834dd..634436f6 100644 --- a/libsepol/include/sepol/policydb/ebitmap.h +++ b/libsepol/include/sepol/policydb/ebitmap.h @@ -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); diff --git a/libsepol/src/ebitmap.c b/libsepol/src/ebitmap.c index 963b8080..7f425349 100644 --- a/libsepol/src/ebitmap.c +++ b/libsepol/src/ebitmap.c @@ -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;