Fix compiling on Mac OS X <10.12 due to clock_gettime()

Closes #813 and #240.

Signed-off-by: Roger A. Light <roger@atchoo.org>
pull/1600/head
Roger A. Light 7 years ago
parent f494a74015
commit fd8002c3e3

@ -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.

@ -30,6 +30,10 @@ Contributors:
#define snprintf sprintf_s
#endif
#ifdef __APPLE__
# include <sys/time.h>
#endif
#include <mosquitto.h>
#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");

Loading…
Cancel
Save