From: Martin Ling Date: Sun, 23 Sep 2018 16:28:11 +0000 (+0100) Subject: Use clock_gettime(CLOCK_MONOTONIC) if available. X-Git-Tag: libserialport-0.1.2~83 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f40ea9d461dd270caefed6460c62ab142476b211;p=libserialport.git Use clock_gettime(CLOCK_MONOTONIC) if available. Should fix #759 except on OSX versions below 10.12, which don't have clock_gettime. --- diff --git a/libserialport_internal.h b/libserialport_internal.h index 3f01b6d..ec15f58 100644 --- a/libserialport_internal.h +++ b/libserialport_internal.h @@ -53,6 +53,7 @@ #include #include #include +#include #include #endif #ifdef __APPLE__ diff --git a/serialport.c b/serialport.c index 07a0aaa..15ca1fd 100644 --- a/serialport.c +++ b/serialport.c @@ -59,7 +59,14 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data, static void get_time(struct timeval *time) { +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + time->tv_sec = ts.tv_sec; + time->tv_usec = ts.tv_nsec / 1000; +#else gettimeofday(time, NULL); +#endif } SP_API enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr)