Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-06-10 15:37:14 +0400
committerFelix Fietkau <nbd@openwrt.org>2013-06-10 15:37:14 +0400
commite5032709b29eb42568c3937a533898728a15efa1 (patch)
tree37bfa31d82aa7223f04456e12f4a2a8bbe1b1cbb /utils.h
parent2851ce7edb3247233b0d07e6d26d5a2ed0478a56 (diff)
utils: add bitfield inline ops
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/utils.h b/utils.h
index 71a4692..db6217e 100644
--- a/utils.h
+++ b/utils.h
@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <stdint.h>
+#include <stdbool.h>
#include <time.h>
/*
@@ -151,4 +152,18 @@ void clock_gettime(int type, struct timespec *tv);
#define __packed __attribute__((packed))
#endif
+#ifndef BITS_PER_LONG
+#define BITS_PER_LONG (8 * sizeof(unsigned long))
+#endif
+
+static inline void bitfield_set(unsigned long *bits, int bit)
+{
+ bits[bit / BITS_PER_LONG] |= (1UL << (bit % BITS_PER_LONG));
+}
+
+static inline bool bitfield_test(unsigned long *bits, int bit)
+{
+ return !!(bits[bit / BITS_PER_LONG] & (1UL << (bit % BITS_PER_LONG)));
+}
+
#endif