summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorTrond Norbye <Trond.Norbye@sun.com>2009-08-26 23:44:30 +0200
committerDustin Sallings <dustin@spy.net>2009-09-02 16:08:07 -0700
commit9791b7794e5439baaced1fd4afa26e09f33cfc36 (patch)
tree65b2efb41ec41a3bfe98ed970ee183e6cba76cf8 /util.c
parentf9bc2b11edf151ce4b33efbe011bd807f14180ca (diff)
downloadmemcached-9791b7794e5439baaced1fd4afa26e09f33cfc36.tar.gz
Issue: #83: Refactor: use htonll or ntohll if the os provides them
Diffstat (limited to 'util.c')
-rw-r--r--util.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/util.c b/util.c
index 083bff4..f935fac 100644
--- a/util.c
+++ b/util.c
@@ -103,3 +103,31 @@ void vperror(const char *fmt, ...) {
perror(buf);
}
+
+#ifndef HAVE_HTONLL
+static uint64_t mc_swap64(uint64_t in) {
+#ifdef ENDIAN_LITTLE
+ /* Little endian, flip the bytes around until someone makes a faster/better
+ * way to do this. */
+ int64_t rv = 0;
+ int i = 0;
+ for(i = 0; i<8; i++) {
+ rv = (rv << 8) | (in & 0xff);
+ in >>= 8;
+ }
+ return rv;
+#else
+ /* big-endian machines don't need byte swapping */
+ return in;
+#endif
+}
+
+uint64_t ntohll(uint64_t val) {
+ return mc_swap64(val);
+}
+
+uint64_t htonll(uint64_t val) {
+ return mc_swap64(val);
+}
+#endif
+