summaryrefslogtreecommitdiff
path: root/bits.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2012-04-20 02:38:26 -0400
committerEric S. Raymond <esr@thyrsus.com>2012-04-20 02:38:26 -0400
commitc8b3668e487d2d35951969ccfa0c2882e96cdfec (patch)
treeeb884bfb9b79068510509d5ec4a61c512c9bacbe /bits.c
parentdf6a5fb51dd4dc37f0bf79bbcd5637e61ff43bf9 (diff)
downloadgpsd-c8b3668e487d2d35951969ccfa0c2882e96cdfec.tar.gz
Get rid of magic number.
Diffstat (limited to 'bits.c')
-rw-r--r--bits.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/bits.c b/bits.c
index f2fc1ff9..34fd4064 100644
--- a/bits.c
+++ b/bits.c
@@ -13,11 +13,10 @@
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
+#include <limits.h>
#include "bits.h"
-#define BITS_PER_BYTE 8
-
uint64_t ubits(char buf[], unsigned int start, unsigned int width, bool le)
/* extract a (zero-origin) bitfield from the buffer as an unsigned big-endian uint64_t */
{
@@ -25,16 +24,16 @@ uint64_t ubits(char buf[], unsigned int start, unsigned int width, bool le)
unsigned int i;
unsigned end;
- /*@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;
+ /*@i1@*/ assert(width <= sizeof(uint64_t) * CHAR_BIT);
+ for (i = start / CHAR_BIT;
+ i < (start + width + CHAR_BIT - 1) / CHAR_BIT; i++) {
+ fld <<= CHAR_BIT;
fld |= (unsigned char)buf[i];
}
- end = (start + width) % BITS_PER_BYTE;
+ end = (start + width) % CHAR_BIT;
if (end != 0) {
- fld >>= (BITS_PER_BYTE - end);
+ fld >>= (CHAR_BIT - end);
}
/*@ -shiftimplementation @*/