diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index fbaefe6d099..5b9b3c47a6b 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -37,10 +37,6 @@ /* Override this file with one for your platform if you need to redefine things. */ -/* For a common case, assume that the platform has a C99-like stdint.h */ - -#include - #if !defined(GPR_NO_AUTODETECT_PLATFORM) #if defined(_WIN64) || defined(WIN64) #define GPR_WIN32 1 @@ -70,20 +66,40 @@ #define GPR_POSIX_TIME 1 #define GPR_GETPID_IN_UNISTD_H 1 #elif defined(__linux__) +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include #define GPR_CPU_LINUX 1 #define GPR_GCC_ATOMIC 1 #define GPR_LINUX 1 #define GPR_LINUX_MULTIPOLL_WITH_EPOLL 1 #define GPR_POSIX_WAKEUP_FD 1 -#define GPR_LINUX_EVENTFD 1 #define GPR_POSIX_SOCKET 1 #define GPR_POSIX_SOCKETADDR 1 #ifdef __GLIBC_PREREQ +#if __GLIBC_PREREQ(2, 9) +#define GPR_LINUX_EVENTFD 1 +#endif +#if __GLIBC_PREREQ(2, 10) +#define GPR_LINUX_SOCKETUTILS 1 +#endif #if __GLIBC_PREREQ(2, 17) #define GPR_LINUX_ENV 1 #endif #endif +#ifndef GPR_LINUX_EVENTFD +#define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 +#endif +#ifndef GPR_LINUX_SOCKETUTILS +#define GPR_POSIX_SOCKETUTILS +#endif #ifndef GPR_LINUX_ENV #define GPR_POSIX_ENV 1 #endif @@ -98,6 +114,9 @@ #define GPR_ARCH_32 1 #endif /* _LP64 */ #elif defined(__APPLE__) +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif #define GPR_CPU_POSIX 1 #define GPR_GCC_ATOMIC 1 #define GPR_POSIX_LOG 1 @@ -123,6 +142,10 @@ #endif #endif /* GPR_NO_AUTODETECT_PLATFORM */ +/* For a common case, assume that the platform has a C99-like stdint.h */ + +#include + /* Cache line alignment */ #ifndef GPR_CACHELINE_SIZE #if defined(__i386__) || defined(__x86_64__) diff --git a/src/core/iomgr/socket_utils_linux.c b/src/core/iomgr/socket_utils_linux.c index 7ef58940c24..f3c22187d73 100644 --- a/src/core/iomgr/socket_utils_linux.c +++ b/src/core/iomgr/socket_utils_linux.c @@ -31,12 +31,9 @@ * */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif #include -#ifdef GPR_LINUX +#ifdef GPR_LINUX_SOCKETUTILS #include "src/core/iomgr/socket_utils_posix.h" diff --git a/src/core/support/file_posix.c b/src/core/support/file_posix.c index cb48b3d52f4..e1765666dbe 100644 --- a/src/core/support/file_posix.c +++ b/src/core/support/file_posix.c @@ -31,19 +31,6 @@ * */ -/* Posix code for gpr fdopen and mkstemp support. */ - -#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 200112L -#undef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200112L -#endif - -/* Don't know why I have to do this for mkstemp, looks like _POSIX_C_SOURCE - should be enough... */ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - #include #ifdef GPR_POSIX_FILE diff --git a/src/core/support/log_posix.c b/src/core/support/log_posix.c index 05f45de1308..36479baeed2 100644 --- a/src/core/support/log_posix.c +++ b/src/core/support/log_posix.c @@ -31,16 +31,6 @@ * */ -#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 200112L -#undef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200112L -#endif - -/* FIXME: "posix" files probably shouldn't depend on _GNU_SOURCE */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include #if defined(GPR_POSIX_LOG) diff --git a/src/core/support/string_posix.c b/src/core/support/string_posix.c index a6bb8058e6c..b6f0cd4af0c 100644 --- a/src/core/support/string_posix.c +++ b/src/core/support/string_posix.c @@ -31,13 +31,6 @@ * */ -/* Posix code for gpr snprintf support. */ - -#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 200112L -#undef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200112L -#endif - #include #ifdef GPR_POSIX_STRING diff --git a/src/core/support/sync_posix.c b/src/core/support/sync_posix.c index a28a4c6bf46..94fc1b0bec3 100644 --- a/src/core/support/sync_posix.c +++ b/src/core/support/sync_posix.c @@ -31,13 +31,6 @@ * */ -/* Posix gpr synchroization support code. */ - -#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 199309L -#undef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 199309L -#endif - #include #ifdef GPR_POSIX_SYNC diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c index 3f2a81ec058..4af537d974b 100644 --- a/src/core/support/time_posix.c +++ b/src/core/support/time_posix.c @@ -31,14 +31,6 @@ * */ -/* Posix code for gpr time support. */ - -/* So we get nanosleep and clock_* */ -#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 199309L -#undef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 199309L -#endif - #include #ifdef GPR_POSIX_TIME