diff options
author | Ruediger Meier | 2016-03-08 09:11:08 +0100 |
---|---|---|
committer | Ruediger Meier | 2016-03-08 14:55:17 +0100 |
commit | d01c0adb8365b1a7194c40133fe1a2d232b49559 (patch) | |
tree | d9aa415028f7c5334ac44aa25638a4667f1697d6 /include/bitops.h | |
parent | tests: don't compare btrfs mount options (diff) | |
download | kernel-qcow2-util-linux-d01c0adb8365b1a7194c40133fe1a2d232b49559.tar.gz kernel-qcow2-util-linux-d01c0adb8365b1a7194c40133fe1a2d232b49559.tar.xz kernel-qcow2-util-linux-d01c0adb8365b1a7194c40133fe1a2d232b49559.zip |
include/bitops: add casts to bswap functions
Based on kernel sources include/uapi/linux/swab.h.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'include/bitops.h')
-rw-r--r-- | include/bitops.h | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/include/bitops.h b/include/bitops.h index 498ec63e7..2d2f88d9c 100644 --- a/include/bitops.h +++ b/include/bitops.h @@ -29,28 +29,33 @@ /* * Fallbacks + * casts are necessary for constants, because we never know how for sure + * how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way. */ #ifndef bswap_16 -# define bswap_16(x) ((((x) & 0x00FF) << 8) | \ - (((x) & 0xFF00) >> 8)) +# define bswap_16(x) ((uint16_t)( \ + (((uint16_t)(x) & 0x00FF) << 8) | \ + (((uint16_t)(x) & 0xFF00) >> 8))) #endif #ifndef bswap_32 -# define bswap_32(x) ((((x) & 0x000000FF) << 24) | \ - (((x) & 0x0000FF00) << 8) | \ - (((x) & 0x00FF0000) >> 8) | \ - (((x) & 0xFF000000) >> 24)) +# define bswap_32(x) ((uint32_t)( \ + (((uint32_t)(x) & 0x000000FF) << 24) | \ + (((uint32_t)(x) & 0x0000FF00) << 8) | \ + (((uint32_t)(x) & 0x00FF0000) >> 8) | \ + (((uint32_t)(x) & 0xFF000000) >> 24))) #endif #ifndef bswap_64 -# define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \ - (((x) & 0x000000000000FF00ULL) << 40) | \ - (((x) & 0x0000000000FF0000ULL) << 24) | \ - (((x) & 0x00000000FF000000ULL) << 8) | \ - (((x) & 0x000000FF00000000ULL) >> 8) | \ - (((x) & 0x0000FF0000000000ULL) >> 24) | \ - (((x) & 0x00FF000000000000ULL) >> 40) | \ - (((x) & 0xFF00000000000000ULL) >> 56)) +# define bswap_64(x) ((uint64_t)( \ + (((uint64_t)(x) & 0x00000000000000FFULL) << 56) | \ + (((uint64_t)(x) & 0x000000000000FF00ULL) << 40) | \ + (((uint64_t)(x) & 0x0000000000FF0000ULL) << 24) | \ + (((uint64_t)(x) & 0x00000000FF000000ULL) << 8) | \ + (((uint64_t)(x) & 0x000000FF00000000ULL) >> 8) | \ + (((uint64_t)(x) & 0x0000FF0000000000ULL) >> 24) | \ + (((uint64_t)(x) & 0x00FF000000000000ULL) >> 40) | \ + (((uint64_t)(x) & 0xFF00000000000000ULL) >> 56))) #endif #ifndef htobe16 |