diff options
author | David Timber <mieabby@gmail.com> | 2021-08-09 17:30:18 +1000 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2021-08-09 19:20:40 +1000 |
commit | eea0a9fbbf1aff1eac1f17914d5c116de98e1d93 (patch) | |
tree | 776e61c070d7afa0df683093b82f327631534341 /src/bitfield.c | |
parent | f6e94a01fd84b693c5a74b8f40edb4dc89836bdf (diff) |
Protocol and build system change ...
* Use autoheader
* Add --enable-minmem
* Add OS code. Bin archive and protocol changed accordingly
* Add instance flags in hostinfo frame. Bitfield util added for this
* Add org_id in hostinfo for lineage record
* SQL schema change: store integer value of hostinfo arch and os
* Remove config.c
* prne_index_nybin() now sets errno
* Instance ids are now preserved for lineage record
* Proone: remove arguments after init
* Fix bug in prne_htbt_ser_bin_meta(): alloc_len is not checked
Diffstat (limited to 'src/bitfield.c')
-rw-r--r-- | src/bitfield.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/bitfield.c b/src/bitfield.c new file mode 100644 index 0000000..cec0304 --- /dev/null +++ b/src/bitfield.c @@ -0,0 +1,37 @@ +#include "bitfield.h" + + +void prne_bf_set (uint8_t *bf, const unsigned int bit, const bool v) { + const unsigned int p = bit / 8; + const unsigned int s = bit - p * 8; + + if (v) { + bf[p] |= 1 << s; + } + else { + bf[p] &= ~(1 << s); + } +} + +bool prne_bf_test (const uint8_t *bf, const unsigned int bit) { + const unsigned int p = bit / 8; + const unsigned int s = bit - p * 8; + + return bf[p] & (1 << s); +} + +void prne_bf_foreach ( + void *ctx, + const uint8_t *bf, + const size_t size, + prne_bf_foreach_ft f) +{ + unsigned int bit = 0; + + for (size_t i = 0; i < size; i += 1) { + for (unsigned int j = 0; j < 8; j += 1) { + f(ctx, bit, (bf[i] & (1 << j)) != 0); + bit += 1; + } + } +} |