From b161c2786ecde8338237774406a98066fc3393f6 Mon Sep 17 00:00:00 2001 From: Jose Santiago Date: Thu, 29 Aug 2019 16:21:18 -0500 Subject: [PATCH 1/4] Fix build Linux GLIBC-2.8 and earlier. Tested on CentOS5 and GLIBC-2.5. Tested on both 32 and 64 bit. --- srtcore/utilities.h | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/srtcore/utilities.h b/srtcore/utilities.h index 93321807c..825567a17 100755 --- a/srtcore/utilities.h +++ b/srtcore/utilities.h @@ -77,6 +77,21 @@ written by // Windows warning disabler #define _CRT_SECURE_NO_WARNINGS 1 +#if defined(__linux__) || defined(__CYGWIN__) + // These macros needed to be defined for some versions of GLIBC to ensure that + // the required macros are defined in system headers included later in this + // file. + #ifndef _BSD_SOURCE + #define _BSD_SOURCE + #endif + #ifndef __USE_BSD + #define __USE_BSD + #endif + #ifndef _DEFAULT_SOURCE + #define _DEFAULT_SOURCE + #endif +#endif + #include "platform_sys.h" // Happens that these are defined, undefine them in advance @@ -110,6 +125,53 @@ written by # include +// GLIBC-2.8 and earlier does not provide these macros. +// See http://linux.die.net/man/3/endian +// From https://gist.github.com/panzi/6856583 +# if !defined(__GLIBC__) \ + || !defined(__GLIBC_MINOR__) \ + || ((__GLIBC__ < 2) \ + || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 9))) +# include +# if defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN) +# define htobe16(x) htons(x) +# define htole16(x) (x) +# define be16toh(x) ntohs(x) +# define le16toh(x) (x) + +# define htobe32(x) htonl(x) +# define htole32(x) (x) +# define be32toh(x) ntohl(x) +# define le32toh(x) (x) + +# define htobe64(x) (((uint64_t)htonl(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)htonl(((uint32_t)(x)))) << 32)) +# define htole64(x) (x) +# define be64toh(x) (((uint64_t)ntohl(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)ntohl(((uint32_t)(x)))) << 32)) +# define le64toh(x) (x) +# elif defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN) +# define htobe16(x) (x) +# define htole16(x) ((((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8))) +# define be16toh(x) (x) +# define le16toh(x) ((((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8))) + +# define htobe32(x) (x) +# define htole32(x) (((uint32_t)htole16(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)htole16(((uint16_t)(x)))) << 16)) +# define be32toh(x) (x) +# define le32toh(x) (((uint32_t)le16toh(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)le16toh(((uint16_t)(x)))) << 16)) + +# define htobe64(x) (x) +# define htole64(x) (((uint64_t)htole32(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)htole32(((uint32_t)(x)))) << 32)) +# define be64toh(x) (x) +# define le64toh(x) (((uint64_t)le32toh(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)le32toh(((uint32_t)(x)))) << 32)) +# else +# error Byte Order not supported or not defined. +# endif +# endif + +#elif defined(__GNU__) + +# include + #elif defined(__APPLE__) # include From 229d1a50c1d834343067f1ce7d93eccbf6506a68 Mon Sep 17 00:00:00 2001 From: Jose Santiago Date: Thu, 29 Aug 2019 16:49:30 -0500 Subject: [PATCH 2/4] Fix for non-GLIBC builds as well. --- srtcore/utilities.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/srtcore/utilities.h b/srtcore/utilities.h index 825567a17..71b1f87c4 100755 --- a/srtcore/utilities.h +++ b/srtcore/utilities.h @@ -128,10 +128,10 @@ written by // GLIBC-2.8 and earlier does not provide these macros. // See http://linux.die.net/man/3/endian // From https://gist.github.com/panzi/6856583 -# if !defined(__GLIBC__) \ - || !defined(__GLIBC_MINOR__) \ +# if defined(__GLIBC__) \ + && ( !defined(__GLIBC_MINOR__) \ || ((__GLIBC__ < 2) \ - || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 9))) + || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 9))) ) # include # if defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN) # define htobe16(x) htons(x) From 66cc56e817b61db553c9b10f6da6c1a6c2dd15fa Mon Sep 17 00:00:00 2001 From: Jose Santiago Date: Tue, 3 Sep 2019 10:52:39 -0500 Subject: [PATCH 3/4] This is not really needed to fix the GLIBC-2.9 and earlier builds so remove it. --- srtcore/utilities.h | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/srtcore/utilities.h b/srtcore/utilities.h index 71b1f87c4..f69a7bf66 100755 --- a/srtcore/utilities.h +++ b/srtcore/utilities.h @@ -77,21 +77,6 @@ written by // Windows warning disabler #define _CRT_SECURE_NO_WARNINGS 1 -#if defined(__linux__) || defined(__CYGWIN__) - // These macros needed to be defined for some versions of GLIBC to ensure that - // the required macros are defined in system headers included later in this - // file. - #ifndef _BSD_SOURCE - #define _BSD_SOURCE - #endif - #ifndef __USE_BSD - #define __USE_BSD - #endif - #ifndef _DEFAULT_SOURCE - #define _DEFAULT_SOURCE - #endif -#endif - #include "platform_sys.h" // Happens that these are defined, undefine them in advance From 6882335439c291dd6c4747131b754089294fc677 Mon Sep 17 00:00:00 2001 From: Jose Santiago Date: Tue, 3 Sep 2019 12:53:44 -0500 Subject: [PATCH 4/4] Remove all unused macros from the GLIBC-2.8 and earlier fix per the most recent review. --- srtcore/utilities.h | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/srtcore/utilities.h b/srtcore/utilities.h index f69a7bf66..cddc6b50c 100755 --- a/srtcore/utilities.h +++ b/srtcore/utilities.h @@ -106,7 +106,7 @@ written by #endif -#if defined(__linux__) || defined(__CYGWIN__) +#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) # include @@ -119,44 +119,23 @@ written by || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 9))) ) # include # if defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN) -# define htobe16(x) htons(x) -# define htole16(x) (x) -# define be16toh(x) ntohs(x) -# define le16toh(x) (x) -# define htobe32(x) htonl(x) # define htole32(x) (x) -# define be32toh(x) ntohl(x) # define le32toh(x) (x) -# define htobe64(x) (((uint64_t)htonl(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)htonl(((uint32_t)(x)))) << 32)) -# define htole64(x) (x) -# define be64toh(x) (((uint64_t)ntohl(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)ntohl(((uint32_t)(x)))) << 32)) -# define le64toh(x) (x) # elif defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN) -# define htobe16(x) (x) + # define htole16(x) ((((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8))) -# define be16toh(x) (x) # define le16toh(x) ((((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8))) -# define htobe32(x) (x) # define htole32(x) (((uint32_t)htole16(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)htole16(((uint16_t)(x)))) << 16)) -# define be32toh(x) (x) # define le32toh(x) (((uint32_t)le16toh(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)le16toh(((uint16_t)(x)))) << 16)) -# define htobe64(x) (x) -# define htole64(x) (((uint64_t)htole32(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)htole32(((uint32_t)(x)))) << 32)) -# define be64toh(x) (x) -# define le64toh(x) (((uint64_t)le32toh(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)le32toh(((uint32_t)(x)))) << 32)) # else # error Byte Order not supported or not defined. # endif # endif -#elif defined(__GNU__) - -# include - #elif defined(__APPLE__) # include