diff options
author | Trond Norbye <Trond.Norbye@sun.com> | 2009-08-26 23:44:30 +0200 |
---|---|---|
committer | Dustin Sallings <dustin@spy.net> | 2009-09-02 16:08:07 -0700 |
commit | 9791b7794e5439baaced1fd4afa26e09f33cfc36 (patch) | |
tree | 65b2efb41ec41a3bfe98ed970ee183e6cba76cf8 /util.c | |
parent | f9bc2b11edf151ce4b33efbe011bd807f14180ca (diff) | |
download | memcached-9791b7794e5439baaced1fd4afa26e09f33cfc36.tar.gz |
Issue: #83: Refactor: use htonll or ntohll if the os provides them
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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 + |