Add SWAP_LE?? and SWAP_BE?? macros, and make things use them. Converts values

to/from little endian or big endian, which is a NOP if that's what the current
platform already is.
This commit is contained in:
Rob Landley
2006-05-29 05:51:12 +00:00
parent 9755197448
commit bba7f08d27
4 changed files with 29 additions and 31 deletions

View File

@ -48,11 +48,6 @@
# define __const const
#endif
#ifndef __THROW
# define __THROW
#endif
#ifndef ATTRIBUTE_UNUSED
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif /* ATTRIBUTE_UNUSED */
@ -118,6 +113,22 @@
# define BB_LITTLE_ENDIAN 1
#endif
#if BB_BIG_ENDIAN
#define SWAP_BE16(x) x
#define SWAP_BE32(x) x
#define SWAP_BE64(x) x
#define SWAP_LE16(x) bswap_16(x)
#define SWAP_LE32(x) bswap_32(x)
#define SWAP_LE64(x) bswap_64(x)
#else
#define SWAP_BE16(x) bswap_16(x)
#define SWAP_BE32(x) bswap_32(x)
#define SWAP_BE64(x) bswap_64(x)
#define SWAP_LE16(x) x
#define SWAP_LE32(x) x
#define SWAP_LE64(x) x
#endif
/* ---- Networking ------------------------------------------ */
#ifndef __APPLE__
# include <arpa/inet.h>