-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from SIPp/fix/3.5/add-missing-le16toh-on-old-…
…glibc-211 build: Fix compile error on CentOS5 and other old Linuxen lacking le1…
- Loading branch information
Showing
3 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,44 @@ | ||
#ifndef ENDIANSHIM_H | ||
#define ENDIANSHIM_H 1 | ||
|
||
#if defined(__CYGWIN) || defined(__LINUX) | ||
#include <endian.h> | ||
#elif defined(__FreeBSD__) | ||
#include <sys/endian.h> | ||
#elif defined(__DARWIN) | ||
/* Fetch HAVE_ENDIAN_H, HAVE_SYS_ENDIAN_H, HAVE_DECL_LE16TOH */ | ||
#include "config.h" | ||
|
||
#ifdef HAVE_ENDIAN_H | ||
/* Linux and friends. */ | ||
# include <endian.h> | ||
#endif | ||
#ifdef HAVE_SYS_ENDIAN_H | ||
/* BSDs */ | ||
# include <sys/endian.h> | ||
#endif | ||
#if defined(__DARWIN) | ||
/* Darwin does something else. */ | ||
#include <libkern/OSByteOrder.h> | ||
#endif | ||
|
||
#ifdef __DARWIN | ||
|
||
#if defined(__DARWIN) | ||
#define le16toh(x) OSSwapLittleToHostInt16(x) | ||
#endif | ||
|
||
/* HP-UX 11 is missing byteswap.h, so we provide our own bswap_16() */ | ||
#ifdef __HPUX | ||
#define bswap_16(x) ((uint16_t)( \ | ||
#elif defined(__HPUX) | ||
/* HPUX is big endian (apparently..) */ | ||
#define le16toh(x) ((uint16_t)( \ | ||
(((uint16_t)(x)) << 8) | \ | ||
(((uint16_t)(x)) >> 8))) | ||
|
||
#define le16toh(x) bswap_16(x) | ||
#elif !defined(HAVE_DECL_LE16TOH) || HAVE_DECL_LE16TOH == 0 | ||
/* le16toh() is missing in glibc before 2.9 */ | ||
#if BYTE_ORDER == BIG_ENDIAN | ||
# define le16toh(x) ((uint16_t)( \ | ||
(((uint16_t)(x)) << 8) | \ | ||
(((uint16_t)(x)) >> 8))) | ||
#elif BYTE_ORDER == LITTLE_ENDIAN | ||
# define le16toh(x) (x) | ||
#else /* BYTE_ORDER == <undefined> */ | ||
# error Unknown endianness | ||
#endif | ||
|
||
#endif /* !HAVE_DECL_LE16TOH */ | ||
|
||
#endif /* ENDIANSHIM_H */ |