1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 #include "config.h"
3 
4 #ifndef CB_DONT_NEED_BYTEORDER
swap64(uint64_t in)5 static uint64_t swap64(uint64_t in) {
6 #ifndef WORDS_BIGENDIAN
7     /* Little endian, flip the bytes around until someone makes a faster/better
8      * way to do this. */
9     uint64_t rv = 0;
10     int i = 0;
11     for (i = 0; i<8; i++) {
12         rv = (rv << 8) | (in & 0xff);
13         in >>= 8;
14     }
15     return rv;
16 #else
17     /* big-endian machines don't need byte swapping */
18     return in;
19 #endif
20 }
21 
22 PLATFORM_PUBLIC_API
ntohll(uint64_t val)23 uint64_t ntohll(uint64_t val) {
24    return swap64(val);
25 }
26 
27 PLATFORM_PUBLIC_API
htonll(uint64_t val)28 uint64_t htonll(uint64_t val) {
29    return swap64(val);
30 }
31 
32 #endif
33