aboutsummaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2012-02-18 12:15:22 +0100
committerAndreas Schneider <asn@cryptomilk.org>2012-02-19 13:26:02 +0100
commit66aaa6f573df2b2f0b8b96a84a16128863a01e1c (patch)
tree0c9f73a11da613dc5ca406bd1ad0184aee3f0146 /src/misc.c
parent3582e386b7173a3da3fad509c6b315b000817302 (diff)
downloadlibssh-66aaa6f573df2b2f0b8b96a84a16128863a01e1c.tar.gz
libssh-66aaa6f573df2b2f0b8b96a84a16128863a01e1c.tar.xz
libssh-66aaa6f573df2b2f0b8b96a84a16128863a01e1c.zip
misc: Improve byte swapping of ntohll().
Fixes sparse warnings.
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/misc.c b/src/misc.c
index 6b051dbc..32884e62 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -288,12 +288,14 @@ uint64_t ntohll(uint64_t a) {
#ifdef WORDS_BIGENDIAN
return a;
#else /* WORDS_BIGENDIAN */
- uint32_t low = (uint32_t)(a & 0xffffffff);
- uint32_t high = (uint32_t)(a >> 32);
- low = ntohl(low);
- high = ntohl(high);
-
- return ((((uint64_t) low) << 32) | ( high));
+ return (((uint64_t)(a) << 56) | \
+ (((uint64_t)(a) << 40) & 0xff000000000000ULL) | \
+ (((uint64_t)(a) << 24) & 0xff0000000000ULL) | \
+ (((uint64_t)(a) << 8) & 0xff00000000ULL) | \
+ (((uint64_t)(a) >> 8) & 0xff000000ULL) | \
+ (((uint64_t)(a) >> 24) & 0xff0000ULL) | \
+ (((uint64_t)(a) >> 40) & 0xff00ULL) | \
+ ((uint64_t)(a) >> 56));
#endif /* WORDS_BIGENDIAN */
}
#endif /* HAVE_NTOHLL */