Merge Trond.
[m6w6/libmemcached] / libmemcached / byteorder.c
1 #include "common.h"
2
3 /* Byte swap a 64-bit number. */
4 static inline uint64_t swap64(uint64_t in)
5 {
6 #ifndef BYTEORDER_BIG_ENDIAN
7 /* Little endian, flip the bytes around until someone makes a faster/better
8 * way to do this. */
9 uint64_t rv= 0;
10 uint8_t x= 0;
11 for(x= 0; x < 8; x++)
12 {
13 rv= (rv << 8) | (in & 0xff);
14 in >>= 8;
15 }
16 return rv;
17 #else
18 /* big-endian machines don't need byte swapping */
19 return in;
20 #endif
21 }
22
23 uint64_t ntohll(uint64_t value)
24 {
25 return swap64(value);
26 }
27
28 uint64_t htonll(uint64_t value)
29 {
30 return swap64(value);
31 }