/****************************************************************************** $Id: swapint.c,v 1.1 2013/02/14 16:58:03 pascal Exp $ *****************************************************************************/ #if HAVE_BYTESWAP_H #include #else #include "EndianSwap/byteswap.h" #endif #include "config.h" #include "EndianSwap/swapint.h" /****************************************************************************** ES_swap_long ############### Swap a long value from big-endian representation to little-endian IN: const long *val : pointer to the long value represented as big-endian RETURN: long : long value represented as little-endian. *****************************************************************************/ long ES_swap_long(const long *val) { #if SIZEOF_LONG == 4 return bswap_32(*val); #elif SIZEOF_LONG == 2 return bswap_16(*val); #else long tmp_val = *val; ES_swap(&tmp_val, SIZEOF_LONG); return(tmp_val); #endif } /****************************************************************************** ES_swap_int ############### Swap a int value from big-endian representation to little-endian IN: const int *val : pointer to the int value represented as big-endian RETURN: int : int value represented as little-endian. *****************************************************************************/ int ES_swap_int(const int *val) { #if SIZEOF_INT == 4 return bswap_32(*val); #elif SIZEOF_INT == 2 return bswap_16(*val); #else int tmp_val = *val; ES_swap(&tmp_val, SIZEOF_INT); return(tmp_val); #endif } /****************************************************************************** ES_swap_short ############### Swap a short value from big-endian representation to little-endian IN: const short *val : pointer to the short value represented as big-endian RETURN: short : short value represented as little-endian. *****************************************************************************/ short ES_swap_short(const short *val) { #if SIZEOF_SHORT == 2 return bswap_16(*val); #else short tmp_val = *val; ES_swap(&tmp_val, SIZEOF_SHORT); return(tmp_val); #endif }