summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>2013-03-02 14:44:13 +0100
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>2013-03-02 14:44:13 +0100
commitf61e396038188da8be6cee24392a230e2791e2b9 (patch)
treefcf9c9b22e5b3521acae381f6f5f740bcbbfcb53 /util.h
parent541d6eed371a2ba24dcf6b6b2452c766f5920078 (diff)
downloadvdr-plugin-inputdev-f61e396038188da8be6cee24392a230e2791e2b9.tar.gz
vdr-plugin-inputdev-f61e396038188da8be6cee24392a230e2791e2b9.tar.bz2
moved common functions in util.h
Diffstat (limited to 'util.h')
-rw-r--r--util.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..d51e022
--- /dev/null
+++ b/util.h
@@ -0,0 +1,52 @@
+/* --*- c -*--
+ * Copyright (C) 2013 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 and/or 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HH_ENSC_VDR_INPUTDEV_UTIL_HH
+#define HH_ENSC_VDR_INPUTDEV_UTIL_HH
+
+#define ARRAY_SIZE(_a) (sizeof(_a) / sizeof(_a)[0])
+
+inline static bool test_bit(unsigned int bit, unsigned long const mask[])
+{
+ unsigned long m = mask[bit / (sizeof mask[0] * 8)];
+ unsigned int i = bit % (sizeof mask[0] * 8);
+
+ return (m & (1u << i)) != 0u;
+}
+
+inline static void set_bit(unsigned int bit, unsigned long mask[])
+{
+ unsigned int i = bit % (sizeof mask[0] * 8);
+
+ mask[bit / (sizeof mask[0] * 8)] |= (1u << i);
+}
+
+inline static void clear_bit(unsigned int bit, unsigned long mask[])
+{
+ unsigned int i = bit % (sizeof mask[0] * 8);
+
+ mask[bit / (sizeof mask[0] * 8)] &= ~(1u << i);
+}
+
+inline static void change_bit(unsigned int bit, unsigned long mask[])
+{
+ if (test_bit(bit, mask))
+ clear_bit(bit, mask);
+ else
+ set_bit(bit, mask);
+}
+
+#endif /* HH_ENSC_VDR_INPUTDEV_UTIL_HH */