<p>Harald Welte <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/12816">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">bitvec: Add bitvec_tailroom_bits() function<br><br>This is similar to msgb_tailroom(): It returns the amount of space<br>left at the end of the bit vector (compared to the current cursor).<br><br>The function returns the number of bits left in the bitvec.<br><br>Change-Id: I8980a6b6d1973b67a2d9ad411c878d956fb428d1<br>---<br>M include/osmocom/core/bitvec.h<br>M tests/bitvec/bitvec_test.c<br>2 files changed, 25 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/core/bitvec.h b/include/osmocom/core/bitvec.h</span><br><span>index da2d4e4..bd10709 100644</span><br><span>--- a/include/osmocom/core/bitvec.h</span><br><span>+++ b/include/osmocom/core/bitvec.h</span><br><span>@@ -93,4 +93,10 @@</span><br><span>  return bytes;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Return the tailroom in number of unused bits remaining in the bit-vector */</span><br><span style="color: hsl(120, 100%, 40%);">+static inline unsigned int bitvec_tailroom_bits(const struct bitvec *bv)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  return bv->data_len*8 - bv->cur_bit;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! @} */</span><br><span>diff --git a/tests/bitvec/bitvec_test.c b/tests/bitvec/bitvec_test.c</span><br><span>index c8795db..fbf5c5d 100644</span><br><span>--- a/tests/bitvec/bitvec_test.c</span><br><span>+++ b/tests/bitvec/bitvec_test.c</span><br><span>@@ -204,6 +204,24 @@</span><br><span>     }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void test_tailroom()</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    struct bitvec b;</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t d[32];</span><br><span style="color: hsl(120, 100%, 40%);">+        unsigned int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     b.data = d;</span><br><span style="color: hsl(120, 100%, 40%);">+   b.data_len = sizeof(d);</span><br><span style="color: hsl(120, 100%, 40%);">+       bitvec_zero(&b);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        OSMO_ASSERT(bitvec_tailroom_bits(&b) == sizeof(d)*8);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   for (i = 0; i < 8*sizeof(d); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+                bitvec_set_bit(&b, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+            OSMO_ASSERT(bitvec_tailroom_bits(&b) == sizeof(d)*8-(i+1));</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int main(int argc, char **argv)</span><br><span> {</span><br><span>       struct bitvec bv;</span><br><span>@@ -311,6 +329,7 @@</span><br><span> </span><br><span>  printf("\nbitvec bytes used.\n");</span><br><span>  test_used_bytes();</span><br><span style="color: hsl(120, 100%, 40%);">+    test_tailroom();</span><br><span> </span><br><span>         printf("\nbitvec ok.\n");</span><br><span>  return 0;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/12816">change 12816</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/12816"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I8980a6b6d1973b67a2d9ad411c878d956fb428d1 </div>
<div style="display:none"> Gerrit-Change-Number: 12816 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder (1000002) </div>
<div style="display:none"> Gerrit-CC: Max <msuraev@sysmocom.de> </div>