diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2015-02-27 15:01:29 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2015-02-27 15:01:29 -0500 |
commit | 718b4c4d7559f879cfa90a451133890988f18669 (patch) | |
tree | a0472ca388a0a653f8694c9a15f0f1327bc36f47 /ntpshmread.c | |
parent | c4335532ee6cc4aaa7d9074f1621496a86a021ae (diff) | |
download | gpsd-718b4c4d7559f879cfa90a451133890988f18669.tar.gz |
clock_gettime() port fix for OS X.
Diffstat (limited to 'ntpshmread.c')
-rw-r--r-- | ntpshmread.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/ntpshmread.c b/ntpshmread.c index 880ef542..0775583d 100644 --- a/ntpshmread.c +++ b/ntpshmread.c @@ -5,6 +5,7 @@ * * Some of this was swiped from the NTPD distribution. */ +#define _XOPEN_SOURCE 600 #include <string.h> #include <stdbool.h> #include <math.h> @@ -72,7 +73,17 @@ enum segstat_t shm_query(/*@null@*/struct shmTime *shm_in, /*@out@*/struct shm_s /*@-type@*//* splint is confused about struct timespec */ shm_stat->tvc.tv_sec = shm_stat->tvc.tv_nsec = 0; + +#ifdef HAVE_CLOCK_GETTIME clock_gettime(CLOCK_REALTIME, &shm_stat->tvc); +#else + { + struct timeval tv; + (void)gettimeofday(&tv, NULL); + shm_stat->tvc.tv_sec = tv.tv_sec; + shm_stat->tvc.tv_nsec = tv.tv_usec * 1000; + } +#endif /* relying on word access to be atomic here */ if (shm->valid == 0) { |