merge.
[m6w6/libmemcached] / libmemcached / byteorder.c
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary:
9 *
10 */
11
12 #include "byteorder.h"
13
14 /* Byte swap a 64-bit number. */
15 #ifndef swap64
16 static inline uint64_t swap64(uint64_t in)
17 {
18 #ifndef WORDS_BIGENDIAN
19 /* Little endian, flip the bytes around until someone makes a faster/better
20 * way to do this. */
21 uint64_t rv= 0;
22 for (uint8_t x= 0; x < 8; x++)
23 {
24 rv= (rv << 8) | (in & 0xff);
25 in >>= 8;
26 }
27 return rv;
28 #else
29 /* big-endian machines don't need byte swapping */
30 return in;
31 #endif // WORDS_BIGENDIAN
32 }
33 #endif
34
35 uint64_t ntohll(uint64_t value)
36 {
37 return swap64(value);
38 }
39
40 uint64_t htonll(uint64_t value)
41 {
42 return swap64(value);
43 }