OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This is a convenience header to pull in the platform-specific | 5 // This is a convenience header to pull in the platform-specific |
6 // headers that define functions for byte-order conversion, | 6 // headers that define functions for byte-order conversion, |
7 // particularly: ntohs(), htons(), ntohl(), htonl(). Prefer including | 7 // particularly: ntohs(), htons(), ntohl(), htonl(). Prefer including |
8 // this file instead of directly writing the #if / #else, since it | 8 // this file instead of directly writing the #if / #else, since it |
9 // avoids duplicating the platform-specific selections. | 9 // avoids duplicating the platform-specific selections. |
10 // This header also provides ntohll() and htonll() for byte-order conversion | 10 // This header also provides ntohll() and htonll() for byte-order conversion |
(...skipping 15 matching lines...) Expand all Loading... |
26 #if defined(COMPILER_MSVC) | 26 #if defined(COMPILER_MSVC) |
27 #include <stdlib.h> | 27 #include <stdlib.h> |
28 #elif defined(OS_MACOSX) | 28 #elif defined(OS_MACOSX) |
29 #include <libkern/OSByteOrder.h> | 29 #include <libkern/OSByteOrder.h> |
30 #elif defined(OS_OPENBSD) | 30 #elif defined(OS_OPENBSD) |
31 #include <sys/endian.h> | 31 #include <sys/endian.h> |
32 #else | 32 #else |
33 #include <byteswap.h> | 33 #include <byteswap.h> |
34 #endif | 34 #endif |
35 | 35 |
36 | |
37 namespace base { | 36 namespace base { |
38 | 37 |
39 // Returns a value with all bytes in |x| swapped, i.e. reverses the endianness. | 38 // Returns a value with all bytes in |x| swapped, i.e. reverses the endianness. |
40 inline uint64 ByteSwap(uint64 x) { | 39 inline uint64 ByteSwap(uint64 x) { |
41 #if defined(COMPILER_MSVC) | 40 #if defined(COMPILER_MSVC) |
42 return _byteswap_uint64(x); | 41 return _byteswap_uint64(x); |
43 #elif defined(OS_MACOSX) | 42 #elif defined(OS_MACOSX) |
44 return OSSwapInt64(x); | 43 return OSSwapInt64(x); |
45 #elif defined(OS_OPENBSD) | 44 #elif defined(OS_OPENBSD) |
46 return swap64(x); | 45 return swap64(x); |
(...skipping 19 matching lines...) Expand all Loading... |
66 return ByteSwap(x); | 65 return ByteSwap(x); |
67 #else | 66 #else |
68 return x; | 67 return x; |
69 #endif | 68 #endif |
70 } | 69 } |
71 | 70 |
72 } // namespace base | 71 } // namespace base |
73 | 72 |
74 | 73 |
75 #endif // BASE_SYS_BYTEORDER_H_ | 74 #endif // BASE_SYS_BYTEORDER_H_ |
OLD | NEW |