Gearman Developer Documentation

libgearman/byteorder.c
Go to the documentation of this file.
00001 /*
00002   Taken from libmemcached.
00003  */
00004 
00005 /* LibMemcached
00006  * Copyright (C) 2006-2009 Brian Aker
00007  * All rights reserved.
00008  *
00009  * Use and distribution licensed under the BSD license.  See
00010  * the COPYING file in the parent directory for full text.
00011  *
00012  * Summary:
00013  *
00014  */
00015 
00016 #include "common.h"
00017 
00018 /* Byte swap a 64-bit number. */
00019 static inline uint64_t swap64(uint64_t in)
00020 {
00021 #ifndef WORDS_BIGENDIAN
00022   /* Little endian, flip the bytes around until someone makes a faster/better
00023    * way to do this. */
00024   uint64_t rv= 0;
00025   uint8_t x= 0;
00026   for(x= 0; x < 8; x++)
00027   {
00028     rv= (rv << 8) | (in & 0xff);
00029     in >>= 8;
00030   }
00031   return rv;
00032 #else
00033   /* big-endian machines don't need byte swapping */
00034   return in;
00035 #endif
00036 }
00037 
00038 uint64_t ntohll(uint64_t value)
00039 {
00040   return swap64(value);
00041 }
00042 
00043 uint64_t htonll(uint64_t value)
00044 {
00045   return swap64(value);
00046 }