| Index: base/sys_byteorder.h
|
| diff --git a/base/sys_byteorder.h b/base/sys_byteorder.h
|
| index 9fcdbba38703cbf0f6dbb43c65a8728ada79837d..1f317714d2529b3d887b9c6bc8b581407575a263 100644
|
| --- a/base/sys_byteorder.h
|
| +++ b/base/sys_byteorder.h
|
| @@ -37,6 +37,28 @@
|
| namespace base {
|
|
|
| // Returns a value with all bytes in |x| swapped, i.e. reverses the endianness.
|
| +inline uint16 ByteSwap(uint16 x) {
|
| +#if defined(COMPILER_MSVC)
|
| + return _byteswap_ushort(x);
|
| +#elif defined(OS_MACOSX)
|
| + return OSSwapInt16(x);
|
| +#elif defined(OS_OPENBSD)
|
| + return swap16(x);
|
| +#else
|
| + return bswap_16(x);
|
| +#endif
|
| +}
|
| +inline uint32 ByteSwap(uint32 x) {
|
| +#if defined(COMPILER_MSVC)
|
| + return _byteswap_ulong(x);
|
| +#elif defined(OS_MACOSX)
|
| + return OSSwapInt32(x);
|
| +#elif defined(OS_OPENBSD)
|
| + return swap32(x);
|
| +#else
|
| + return bswap_32(x);
|
| +#endif
|
| +}
|
| inline uint64 ByteSwap(uint64 x) {
|
| #if defined(COMPILER_MSVC)
|
| return _byteswap_uint64(x);
|
| @@ -51,7 +73,21 @@ inline uint64 ByteSwap(uint64 x) {
|
|
|
| // Converts the bytes in |x| from network to host order (endianness), and
|
| // returns the result.
|
| -inline uint64 ntohll(uint64 x) {
|
| +inline uint16 NetToHost16(uint16 x) {
|
| +#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
| + return ByteSwap(x);
|
| +#else
|
| + return x;
|
| +#endif
|
| +}
|
| +inline uint32 NetToHost32(uint32 x) {
|
| +#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
| + return ByteSwap(x);
|
| +#else
|
| + return x;
|
| +#endif
|
| +}
|
| +inline uint64 NetToHost64(uint64 x) {
|
| #if defined(ARCH_CPU_LITTLE_ENDIAN)
|
| return ByteSwap(x);
|
| #else
|
| @@ -61,7 +97,21 @@ inline uint64 ntohll(uint64 x) {
|
|
|
| // Converts the bytes in |x| from host to network order (endianness), and
|
| // returns the result.
|
| -inline uint64 htonll(uint64 x) {
|
| +inline uint16 HostToNet16(uint16 x) {
|
| +#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
| + return ByteSwap(x);
|
| +#else
|
| + return x;
|
| +#endif
|
| +}
|
| +inline uint32 HostToNet32(uint32 x) {
|
| +#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
| + return ByteSwap(x);
|
| +#else
|
| + return x;
|
| +#endif
|
| +}
|
| +inline uint64 HostToNet64(uint64 x) {
|
| #if defined(ARCH_CPU_LITTLE_ENDIAN)
|
| return ByteSwap(x);
|
| #else
|
|
|