# HG changeset patch # User Matti Hamalainen # Date 1641467536 -7200 # Node ID b415b70254fae653e363e706edc32b373d3b3402 # Parent 29e44a58bc7333c87e48cb76ffffe5635f9bdea5 Add set_bit/test_bit helpers. diff -r 29e44a58bc73 -r b415b70254fa th_util.h --- a/th_util.h Sat Jan 01 16:17:31 2022 +0200 +++ b/th_util.h Thu Jan 06 13:12:16 2022 +0200 @@ -152,6 +152,18 @@ #define th_free_r(ptr) th_free_r_real((void **) ptr) +#define th_test_bit(pdata, nbit) \ + (pdata[nbit >> 3] & (1 << (nbit & 7))) + +static inline void th_set_bit(uint8_t *pdata, const size_t nbit, const int value) +{ + if (value) + pdata[nbit >> 3] |= (1 << (nbit & 7)); + else + pdata[nbit >> 3] &= ~(1 << (nbit & 7)); +} + + #ifdef __cplusplus } #endif