changeset 727:b415b70254fa

Add set_bit/test_bit helpers.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 06 Jan 2022 13:12:16 +0200
parents 29e44a58bc73
children 18a19d052f94
files th_util.h
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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