diff mbox series

[ovs-dev] timeval: Check for OS-provided clock_gettime on macOS

Message ID 20171028153830.13463-1-richard@richard-oliver.co.uk
State Accepted
Headers show
Series [ovs-dev] timeval: Check for OS-provided clock_gettime on macOS | expand

Commit Message

Richard Oliver Oct. 28, 2017, 3:38 p.m. UTC
[Problem]
Compilation error on newer versions of macOS (Sierra onwards) due to
multiple declarations of clock_gettime.

[Solution]
Have configure check for clock_gettime and check this result in
timeval to avoid incorrectly declaring/defining clock_gettime again.

[Testing]
Source code now successfully builds on macOS.

Signed-off-by: Richard Oliver <richard@richard-oliver.co.uk>
---
 configure.ac  | 2 +-
 lib/timeval.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Ben Pfaff Oct. 30, 2017, 4:56 p.m. UTC | #1
On Sat, Oct 28, 2017 at 04:38:30PM +0100, Richard Oliver wrote:
> [Problem]
> Compilation error on newer versions of macOS (Sierra onwards) due to
> multiple declarations of clock_gettime.
> 
> [Solution]
> Have configure check for clock_gettime and check this result in
> timeval to avoid incorrectly declaring/defining clock_gettime again.
> 
> [Testing]
> Source code now successfully builds on macOS.
> 
> Signed-off-by: Richard Oliver <richard@richard-oliver.co.uk>

Thanks a lot, I applied this to master and branch-2.8.
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index 27425991a..9e0081832 100644
--- a/configure.ac
+++ b/configure.ac
@@ -112,7 +112,7 @@  AC_CHECK_MEMBERS([struct mmsghdr.msg_len], [], [], [[#include <sys/socket.h>]])
 AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_scope_id], [], [],
   [[#include <sys/socket.h>
 #include <netinet/in.h>]])
-AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r sendmmsg])
+AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r sendmmsg clock_gettime])
 AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h stdatomic.h])
 AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include <sys/types.h>
 #include <net/if.h>]])
diff --git a/lib/timeval.c b/lib/timeval.c
index b50ff85a5..b60bf3067 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -41,7 +41,7 @@ 
 
 VLOG_DEFINE_THIS_MODULE(timeval);
 
-#if defined(_WIN32) || defined(__MACH__)
+#if !defined(HAVE_CLOCK_GETTIME)
 typedef unsigned int clockid_t;
 static int clock_gettime(clock_t id, struct timespec *ts);
 
@@ -52,7 +52,7 @@  static int clock_gettime(clock_t id, struct timespec *ts);
 #ifndef CLOCK_REALTIME
 #define CLOCK_REALTIME 2
 #endif
-#endif /* defined(_WIN32) || defined(__MACH__) */
+#endif /* !defined(HAVE_CLOCK_GETTIME) */
 
 #ifdef _WIN32
 /* Number of 100 ns intervals from January 1, 1601 till January 1, 1970. */
@@ -453,7 +453,7 @@  clock_gettime(clock_t id, struct timespec *ts)
 }
 #endif /* _WIN32 */
 
-#ifdef __MACH__
+#if defined(__MACH__) && !defined(HAVE_CLOCK_GETTIME)
 #include <mach/clock.h>
 #include <mach/mach.h>
 static int