diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2020-09-11 01:15:48 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2020-09-11 01:15:48 +0100 |
commit | 92483316beaab8082635c35a5aca7cbe18b4d9f3 (patch) | |
tree | 7f4f64abfb0aa52c60c240e7a1eaed836959f12a | |
parent | 2644c6fc2c99b63936c3e505340e597b1c1f4fa7 (diff) | |
download | pack-92483316beaab8082635c35a5aca7cbe18b4d9f3.tar.gz pack-92483316beaab8082635c35a5aca7cbe18b4d9f3.tar.xz pack-92483316beaab8082635c35a5aca7cbe18b4d9f3.zip |
unpack: Add BITMASK helper macro
-rw-r--r-- | unpack.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -18,6 +18,8 @@ enum endian { BIG, LITTLE }; +#define BITMASK(n) (UINTMAX_MAX >> (sizeof (uintmax_t) * CHAR_BIT - n)) + static float ieee754tof(uintmax_t b) { bool isneg; @@ -144,7 +146,7 @@ enum pack_status unpack(void *buf_, size_t size, const char *fmt, ...) if (!(val.u & (UINTMAX_C(1) << (s * 8 - 1)))) { vals = val.u; } else { - uintmax_t offt = UINTMAX_MAX >> (sizeof offt * CHAR_BIT - s * 8); + uintmax_t offt = BITMASK(s * 8); vals = val.u - offt - 1; } val.s = vals; |