Use clock_gettime(CLOCK_MONOTONIC) if available.

Should fix #759 except on OSX versions below 10.12, which don't
have clock_gettime.
This commit is contained in:
Martin Ling 2018-09-23 17:28:11 +01:00
parent 46bdc20c26
commit f40ea9d461
2 changed files with 8 additions and 0 deletions

View File

@ -53,6 +53,7 @@
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <time.h>
#include <poll.h>
#endif
#ifdef __APPLE__

View File

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