Skip to content

Commit

Permalink
Merge pull request #257 from SIPp/fix/3.5/add-missing-le16toh-on-old-…
Browse files Browse the repository at this point in the history
…glibc-211

build: Fix compile error on CentOS5 and other old Linuxen lacking le1…
  • Loading branch information
wdoekes authored Oct 1, 2016
2 parents 957e23c + 03d6566 commit a7069b9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
12 changes: 11 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ AM_CONDITIONAL(HAVE_EPOLL, test "$epoll" = "yes")
# ==================== checks for header files ==========================

AC_FUNC_ALLOCA
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
AC_CHECK_HEADERS([arpa/inet.h endian.h fcntl.h limits.h netdb.h netinet/in.h stdlib.h string.h sys/endian.h sys/socket.h sys/time.h unistd.h])

# ===== checks for typedefs, structures and compiler characteristics ====

Expand All @@ -236,6 +236,16 @@ AC_FUNC_FORK
#AC_FUNC_STRTOD
AC_CHECK_FUNCS([alarm dup2 floor gethostname gettimeofday inet_ntoa memmove memset pow regcomp socket sqrt strcasecmp strchr strcspn strdup strerror strncasecmp strrchr strstr strtol strtoul strtoull])

# Check for le16toh in both endian.h and sys/endian.h (for BSD).
AC_CHECK_DECLS([le16toh], [], [],
[#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#ifdef HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
#endif])


# ==================== check for clang/gmock workaround =================

# clang++ falls over the use of is_default_constructible, suggesting
Expand Down
10 changes: 10 additions & 0 deletions include/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@
/* define if the compiler supports basic C++11 syntax */
#undef HAVE_CXX11

/* Define to 1 if you have the declaration of `le16toh', and to 0 if you
don't. */
#undef HAVE_DECL_LE16TOH

/* Define to 1 if you have the `dup2' function. */
#undef HAVE_DUP2

/* Define to 1 if you have the <endian.h> header file. */
#undef HAVE_ENDIAN_H

/* This platform supports epoll(7). */
#undef HAVE_EPOLL

Expand Down Expand Up @@ -183,6 +190,9 @@
/* Define to 1 if you have the `strtoull' function. */
#undef HAVE_STRTOULL

/* Define to 1 if you have the <sys/endian.h> header file. */
#undef HAVE_SYS_ENDIAN_H

/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H

Expand Down
41 changes: 30 additions & 11 deletions include/endianshim.h
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 */

0 comments on commit a7069b9

Please sign in to comment.