summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-09-04 10:33:56 -0400
committerDwight <dmerriman@gmail.com>2008-09-04 10:33:56 -0400
commit5deec924696d34505ba1bb75cebfab4a66ddec33 (patch)
treebd184fd5ad4f70ed0d99b4a8c96b51c2d54a734c /util
parent8cac7e4dc4c1102b69598ba6b1e60df8d8e1dcdd (diff)
downloadmongo-5deec924696d34505ba1bb75cebfab4a66ddec33.tar.gz
endian check capability
repl work in progress cleanup
Diffstat (limited to 'util')
-rw-r--r--util/goodies.h15
-rw-r--r--util/util.cpp2
2 files changed, 17 insertions, 0 deletions
diff --git a/util/goodies.h b/util/goodies.h
index 7c38f8d1e93..a400a39b280 100644
--- a/util/goodies.h
+++ b/util/goodies.h
@@ -199,3 +199,18 @@ inline bool endsWith(const char *p, const char *suffix) {
return strcmp(p + a - b, suffix) == 0;
}
+#include "boost/detail/endian.hpp"
+
+inline unsigned long swapEndian(unsigned long x) {
+ return
+ ((x & 0xff) << 24) |
+ ((x & 0xff00) << 8) |
+ ((x & 0xff0000) >> 8) |
+ ((x & 0xff000000) >> 24);
+}
+
+#if defined(BOOST_LITTLE_ENDIAN)
+inline unsigned long fixEndian(unsigned long x) { return x; }
+#else
+inline unsigned long fixEndian(unsigned long x) { return swapEndian(x); }
+#endif
diff --git a/util/util.cpp b/util/util.cpp
index 51fb7dfc7f7..c78767f3a69 100644
--- a/util/util.cpp
+++ b/util/util.cpp
@@ -68,5 +68,7 @@ struct UtilTest {
assert( endsWith("abcde", "de") );
assert( !endsWith("abcde", "dasdfasdfashkfde") );
+ assert( swapEndian(0x01020304) == 0x04030201 );
+
}
} utilTest;