f407fa039c01f62fcf4405137a43d80c67796582
[awesomized/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 #ifndef BYTEORDER_BIG_ENDIAN
6 /* Little endian, flip the bytes around until someone makes a faster/better
7 * way to do this. */
8 uint64_t rv= 0;
9 int i= 0;
10 for(i= 0; i < 8; i++)
11 {
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 uint64_t ntohll(uint64_t value) {
23 return swap64(value);
24 }
25
26 uint64_t htonll(uint64_t value) {
27 return swap64(value);
28 }