Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: base/sys_byteorder.h

Issue 10088001: Fixing issues with alignment, undefined behaviour and endianness in the FieldTrial::HashName functi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 header defines cross-platform ByteSwap() implementations for 16, 32 and 5 // This header defines cross-platform ByteSwap() implementations for 16, 32 and
6 // 64-bit values, and NetToHostXX() / HostToNextXX() functions equivalent to 6 // 64-bit values, and NetToHostXX() / HostToNextXX() functions equivalent to
7 // the traditional ntohX() and htonX() functions. 7 // the traditional ntohX() and htonX() functions.
8 // Use the functions defined here rather than using the platform-specific 8 // Use the functions defined here rather than using the platform-specific
9 // functions directly. 9 // functions directly.
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return _byteswap_uint64(x); 62 return _byteswap_uint64(x);
63 #elif defined(OS_MACOSX) 63 #elif defined(OS_MACOSX)
64 return OSSwapInt64(x); 64 return OSSwapInt64(x);
65 #elif defined(OS_OPENBSD) 65 #elif defined(OS_OPENBSD)
66 return swap64(x); 66 return swap64(x);
67 #else 67 #else
68 return bswap_64(x); 68 return bswap_64(x);
69 #endif 69 #endif
70 } 70 }
71 71
72 // Converts the bytes in |x| from host order (endianness) to little endian, and
73 // returns the result.
74 inline uint16 ByteSwapToLE16(uint16 x) {
75 #if defined(ARCH_CPU_LITTLE_ENDIAN)
76 return x;
77 #else
78 return ByteSwap(x);
79 #endif
80 }
81 inline uint32 ByteSwapToLE32(uint32 x) {
82 #if defined(ARCH_CPU_LITTLE_ENDIAN)
83 return x;
84 #else
85 return ByteSwap(x);
86 #endif
87 }
88 inline uint64 ByteSwapToLE64(uint64 x) {
89 #if defined(ARCH_CPU_LITTLE_ENDIAN)
90 return x;
91 #else
92 return ByteSwap(x);
93 #endif
Ilya Sherman 2012/04/13 20:19:20 Hmm, why are you adding these functions rather tha
jwd 2012/04/13 20:33:44 We decided that we wanted the values in little-end
Ilya Sherman 2012/04/13 21:27:33 Ok, fair enough. Thanks :)
94 }
95
72 // Converts the bytes in |x| from network to host order (endianness), and 96 // Converts the bytes in |x| from network to host order (endianness), and
73 // returns the result. 97 // returns the result.
74 inline uint16 NetToHost16(uint16 x) { 98 inline uint16 NetToHost16(uint16 x) {
75 #if defined(ARCH_CPU_LITTLE_ENDIAN) 99 #if defined(ARCH_CPU_LITTLE_ENDIAN)
76 return ByteSwap(x); 100 return ByteSwap(x);
77 #else 101 #else
78 return x; 102 return x;
79 #endif 103 #endif
80 } 104 }
81 inline uint32 NetToHost32(uint32 x) { 105 inline uint32 NetToHost32(uint32 x) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return ByteSwap(x); 138 return ByteSwap(x);
115 #else 139 #else
116 return x; 140 return x;
117 #endif 141 #endif
118 } 142 }
119 143
120 } // namespace base 144 } // namespace base
121 145
122 146
123 #endif // BASE_SYS_BYTEORDER_H_ 147 #endif // BASE_SYS_BYTEORDER_H_
OLDNEW
« no previous file with comments | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698