diff options
Diffstat (limited to 'main/strcompat.c')
-rw-r--r-- | main/strcompat.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/main/strcompat.c b/main/strcompat.c index 7f9d2813b..156809003 100644 --- a/main/strcompat.c +++ b/main/strcompat.c @@ -334,3 +334,55 @@ int getloadavg(double *list, int nelem) #endif /* linux */ #endif /* !HAVE_GETLOADAVG */ +#ifndef HAVE_NTOHLL +uint64_t ntohll(uint64_t net64) +{ +#if BYTE_ORDER == BIG_ENDIAN + return net64; +#elif BYTE_ORDER == LITTLE_ENDIAN + union { + unsigned char c[8]; + uint64_t u; + } number; + number.u = net64; + return + (((uint64_t) number.c[0]) << 0) | + (((uint64_t) number.c[1]) << 8) | + (((uint64_t) number.c[2]) << 16) | + (((uint64_t) number.c[3]) << 24) | + (((uint64_t) number.c[4]) << 32) | + (((uint64_t) number.c[5]) << 40) | + (((uint64_t) number.c[6]) << 48) | + (((uint64_t) number.c[7]) << 56); +#else + #error "Unknown byte order" +#endif +} +#endif + +#ifndef HAVE_HTONLL +uint64_t htonll(uint64_t host64) +{ +#if BYTE_ORDER == BIG_ENDIAN + return host64; +#elif BYTE_ORDER == LITTLE_ENDIAN + union { + unsigned char c[8]; + uint64_t u; + } number; + number.u = host64; + return + (((uint64_t) number.c[0]) << 0) | + (((uint64_t) number.c[1]) << 8) | + (((uint64_t) number.c[2]) << 16) | + (((uint64_t) number.c[3]) << 24) | + (((uint64_t) number.c[4]) << 32) | + (((uint64_t) number.c[5]) << 40) | + (((uint64_t) number.c[6]) << 48) | + (((uint64_t) number.c[7]) << 56); +#else + #error "Unknown byte order" +#endif +} +#endif + |