aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/core
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-02-03 12:04:46 +0100
committerHarald Welte <laforge@gnumonks.org>2019-02-05 09:24:17 +0000
commitae7966d145965452a325a33ca6334b6d6fe061a6 (patch)
tree153502bda3057136cf69fe9cb247e65500a6b321 /include/osmocom/core
parent71806ddb29f5acc2ea78a08756ff2b82fd6d618e (diff)
bitvec: Add bitvec_bytes_used() function
This new bitvec API function returns the number of bytes used in a given bit-vector. Change-Id: Id4bd7f7543f5b0f4f6f876e283bd065039c37646
Diffstat (limited to 'include/osmocom/core')
-rw-r--r--include/osmocom/core/bitvec.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/osmocom/core/bitvec.h b/include/osmocom/core/bitvec.h
index c9bab39..da2d4e4 100644
--- a/include/osmocom/core/bitvec.h
+++ b/include/osmocom/core/bitvec.h
@@ -84,4 +84,13 @@ unsigned int bitvec_add_array(struct bitvec *bv, const uint32_t *array,
unsigned int array_len, bool dry_run,
unsigned int num_bits);
+/*! Return the number of bytes used within the bit vector */
+static inline unsigned int bitvec_used_bytes(const struct bitvec *bv)
+{
+ unsigned int bytes = bv->cur_bit/8;
+ if (bv->cur_bit%8)
+ bytes++;
+ return bytes;
+}
+
/*! @} */