diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2012-04-20 02:38:26 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2012-04-20 02:38:26 -0400 |
commit | c8b3668e487d2d35951969ccfa0c2882e96cdfec (patch) | |
tree | eb884bfb9b79068510509d5ec4a61c512c9bacbe /bits.c | |
parent | df6a5fb51dd4dc37f0bf79bbcd5637e61ff43bf9 (diff) | |
download | gpsd-c8b3668e487d2d35951969ccfa0c2882e96cdfec.tar.gz |
Get rid of magic number.
Diffstat (limited to 'bits.c')
-rw-r--r-- | bits.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -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 @*/ |