summaryrefslogtreecommitdiff
path: root/bits.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-01-25 16:59:20 -0500
committerEric S. Raymond <esr@thyrsus.com>2011-01-25 16:59:20 -0500
commit1d996ee56568b8fa8a03b386eda830a8bb543781 (patch)
treec3a049eb4eb798a3c2d608e0bb5f3343cc4ebbca /bits.c
parentf258275ffec682cceed56d628853c68b02a07770 (diff)
downloadgpsd-1d996ee56568b8fa8a03b386eda830a8bb543781.tar.gz
We no longer rely on long long to be 64 bits.
All regression tests pass.
Diffstat (limited to 'bits.c')
-rw-r--r--bits.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/bits.c b/bits.c
index a7e68ddb..04899c61 100644
--- a/bits.c
+++ b/bits.c
@@ -4,13 +4,13 @@
* BSD terms apply: see the file COPYING in the distribution root for details.
*
* Bitfield extraction functions. In each, start is a bit index - not
- * a byte index - and width is a bit width. The width bounded above by
- * the bit width of a long long, which is 64 bits in all standard data
- * models for 32- and 64-bit processors.
+ * a byte index - and width is a bit width. The width is bounded above by
+ * 64 bits.
*
* The sbits() function assumes twos-complement arithmetic.
*/
#include <assert.h>
+#include <stdint.h>
#include "bits.h"
#ifdef DEBUG
@@ -20,14 +20,14 @@
#define BITS_PER_BYTE 8
-unsigned long long ubits(char buf[], unsigned int start, unsigned int width)
-/* extract a (zero-origin) bitfield from the buffer as an unsigned big-endian long long */
+uint64_t ubits(char buf[], unsigned int start, unsigned int width)
+/* extract a (zero-origin) bitfield from the buffer as an unsigned big-endian uint64_t */
{
- unsigned long long fld = 0;
+ uint64_t fld = 0;
unsigned int i;
unsigned end;
- /*@i1@*/ assert(width <= sizeof(long long) * BITS_PER_BYTE);
+ /*@i1@*/ assert(width <= sizeof(uint64_t) * BITS_PER_BYTE);
for (i = start / BITS_PER_BYTE;
i < (start + width + BITS_PER_BYTE - 1) / BITS_PER_BYTE; i++) {
fld <<= BITS_PER_BYTE;
@@ -64,10 +64,10 @@ unsigned long long ubits(char buf[], unsigned int start, unsigned int width)
return fld;
}
-signed long long sbits(char buf[], unsigned int start, unsigned int width)
+int64_t sbits(char buf[], unsigned int start, unsigned int width)
/* extract a bitfield from the buffer as a signed big-endian long */
{
- unsigned long long fld = ubits(buf, start, width);
+ uint64_t fld = ubits(buf, start, width);
#ifdef SDEBUG
(void)fprintf(stderr, "sbits(%d, %d) extracts %llx\n", start, width, fld);
@@ -83,8 +83,8 @@ signed long long sbits(char buf[], unsigned int start, unsigned int width)
}
#ifdef SDEBUG
(void)fprintf(stderr, "sbits(%d, %d) returns %lld\n", start, width,
- (signed long long)fld);
+ (int64_t)fld);
#endif /* SDEBUG */
- return (signed long long)fld;
+ return (int64_t)fld;
/*@ -relaxtypes */
}