Harald Welte has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/12816 )

Change subject: bitvec: Add bitvec_tailroom_bits() function
......................................................................

bitvec: Add bitvec_tailroom_bits() function

This is similar to msgb_tailroom(): It returns the amount of space
left at the end of the bit vector (compared to the current cursor).

The function returns the number of bits left in the bitvec.

Change-Id: I8980a6b6d1973b67a2d9ad411c878d956fb428d1
---
M include/osmocom/core/bitvec.h
M tests/bitvec/bitvec_test.c
2 files changed, 25 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/include/osmocom/core/bitvec.h b/include/osmocom/core/bitvec.h
index da2d4e4..bd10709 100644
--- a/include/osmocom/core/bitvec.h
+++ b/include/osmocom/core/bitvec.h
@@ -93,4 +93,10 @@
        return bytes;
 }

+/*! Return the tailroom in number of unused bits remaining in the bit-vector */
+static inline unsigned int bitvec_tailroom_bits(const struct bitvec *bv)
+{
+       return bv->data_len*8 - bv->cur_bit;
+}
+
 /*! @} */
diff --git a/tests/bitvec/bitvec_test.c b/tests/bitvec/bitvec_test.c
index c8795db..fbf5c5d 100644
--- a/tests/bitvec/bitvec_test.c
+++ b/tests/bitvec/bitvec_test.c
@@ -204,6 +204,24 @@
        }
 }

+static void test_tailroom()
+{
+       struct bitvec b;
+       uint8_t d[32];
+       unsigned int i;
+
+       b.data = d;
+       b.data_len = sizeof(d);
+       bitvec_zero(&b);
+
+       OSMO_ASSERT(bitvec_tailroom_bits(&b) == sizeof(d)*8);
+
+       for (i = 0; i < 8*sizeof(d); i++) {
+               bitvec_set_bit(&b, 1);
+               OSMO_ASSERT(bitvec_tailroom_bits(&b) == sizeof(d)*8-(i+1));
+       }
+}
+
 int main(int argc, char **argv)
 {
        struct bitvec bv;
@@ -311,6 +329,7 @@

        printf("\nbitvec bytes used.\n");
        test_used_bytes();
+       test_tailroom();

        printf("\nbitvec ok.\n");
        return 0;

--
To view, visit https://gerrit.osmocom.org/12816
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I8980a6b6d1973b67a2d9ad411c878d956fb428d1
Gerrit-Change-Number: 12816
Gerrit-PatchSet: 3
Gerrit-Owner: Harald Welte <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-CC: Max <[email protected]>

Reply via email to