summaryrefslogtreecommitdiff
path: root/bits.h
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2008-07-16 22:42:11 +0000
committerEric S. Raymond <esr@thyrsus.com>2008-07-16 22:42:11 +0000
commit4ca672e113bd7ab6c106c41d53b10a4828228b4a (patch)
treecbb7a3fc813135f5d2e7ac2d22a113888d60b6f8 /bits.h
parent70c598e28e5cabe3694dcc4a894838a14a7cde15 (diff)
downloadgpsd-4ca672e113bd7ab6c106c41d53b10a4828228b4a.tar.gz
Factor out the bitfield functions, fix a bug in one, add tests.
Diffstat (limited to 'bits.h')
-rw-r--r--bits.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/bits.h b/bits.h
index c73ac8b4..07e2d0d3 100644
--- a/bits.h
+++ b/bits.h
@@ -2,9 +2,9 @@
/*
* bits.h - extract binary data from message buffer
*
- * These macros extract bytes, words, longwords, floats or doubles from
- * a message that contains these items in either MSB-first or LSB-first
- * byte order.
+ * These macros extract bytes, words, longwords, floats, doubles, or
+ * bitfields of arbitrary length and size from a message that contains
+ * these items in either MSB-first or LSB-first byte order.
*
* By defining the GET_ORIGIN and PUT_ORIGIN macros before including
* this header, it's possible to change the origin of the indexing.
@@ -16,6 +16,7 @@
* The use of fixed-length types in the casts enforces these.
* Both 32- and 64-bit systems with gcc are OK with this set.
*/
+#include <stdint.h>
#ifndef BITS_H
#define BITS_H
@@ -80,3 +81,7 @@ union long_double {
| (buf[2*(n)+1] << 24))
#define getstringz(to, from, s, e) \
(void)memcpy(to, from+2*(s)-2, 2*((e)-(s)+1))
+
+/* bitfield extraction */
+extern unsigned long long ubits(char buf[], unsigned int, unsigned int);
+extern signed long long sbits(char buf[], unsigned int, unsigned int);