From fd8002c3e3a0eeaea3e298948366ce3d91d9ba91 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 15 Aug 2018 14:53:44 +0100 Subject: [PATCH] Fix compiling on Mac OS X <10.12 due to clock_gettime() Closes #813 and #240. Signed-off-by: Roger A. Light --- ChangeLog.txt | 1 + client/sub_client_output.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index a1dae2f0..d50b8447 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -35,6 +35,7 @@ Library: Clients: - When compiled using WITH_TLS=no, the default port was incorrectly being set to -1. This has been fixed. +- Fix compiling on Mac OS X <10.12. Closes #813 and #240. Build: - Fixes for building on NetBSD. Closes #258. diff --git a/client/sub_client_output.c b/client/sub_client_output.c index 90b5b58a..83afec8d 100644 --- a/client/sub_client_output.c +++ b/client/sub_client_output.c @@ -30,6 +30,10 @@ Contributors: #define snprintf sprintf_s #endif +#ifdef __APPLE__ +# include +#endif + #include #include "client_shared.h" @@ -38,6 +42,8 @@ static int get_time(struct tm **ti, long *ns) { #ifdef WIN32 SYSTEMTIME st; +#elif defined(__APPLE__) + struct timeval tv; #else struct timespec ts; #endif @@ -48,6 +54,10 @@ static int get_time(struct tm **ti, long *ns) GetLocalTime(&st); *ns = st.wMilliseconds*1000000L; +#elif defined(__APPLE__) + gettimeofday(&tv, NULL); + s = tv.tv_sec; + *ns = tv.tv_usec*1000; #else if(clock_gettime(CLOCK_REALTIME, &ts) != 0){ fprintf(stderr, "Error obtaining system time.\n");