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

Side by Side Diff: base/sys_byteorder.h

Issue 9614004: Avoid loading ws2_32.dll just to get htons() and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make patch 87% less ugly by moving macro hacks closer to failing code. Created 8 years, 9 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 | « no previous file | crypto/p224.cc » ('j') | crypto/p224.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_
OLDNEW
« no previous file with comments | « no previous file | crypto/p224.cc » ('j') | crypto/p224.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698