From 58c084fbda37548ef1b00125de956ecd72adec2f Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sun, 13 Mar 2011 20:23:23 +0000 Subject: [PATCH] (trunk libT) better implementation of tr_htonll() and tr_ntohll() --- libtransmission/utils.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 5a8a69f11..430a08c6a 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -1653,28 +1653,24 @@ tr_realpath( const char * path, char * resolved_path ) ***/ uint64_t -tr_ntohll( uint64_t v ) +tr_htonll( uint64_t x ) { -#ifdef HAVE_NTOHLL - return ntohll( v ); +#ifdef HAVE_HTONLL + return htonll( x ); #else - union { unsigned long lv[2]; unsigned long long llv; } u; - u.lv[0] = ntohl(v >> 32); - u.lv[1] = ntohl(v & 0xFFFFFFFFULL); - return u.llv; + return (((uint64_t)(htonl((int)((x << 32) >> 32))) << 32) | + (unsigned int)htonl(((int)(x >> 32)))); #endif } uint64_t -tr_htonll( uint64_t v ) +tr_ntohll( uint64_t x ) { -#ifdef HAVE_HTONLL - return htonll( v ); +#ifdef HAVE_NTOHLL + return ntohll( x ); #else - union { unsigned long lv[2]; unsigned long long llv; } u; - u.lv[0] = htonl(v >> 32); - u.lv[1] = htonl(v & 0xFFFFFFFFULL); - return u.llv; + return (((uint64_t)(ntohl((int)((x << 32) >> 32))) << 32) | + (unsigned int)ntohl(((int)(x >> 32)))); #endif } -- 2.40.0