summaryrefslogtreecommitdiff
path: root/ntpshmread.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-02-27 15:01:29 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-02-27 15:01:29 -0500
commit718b4c4d7559f879cfa90a451133890988f18669 (patch)
treea0472ca388a0a653f8694c9a15f0f1327bc36f47 /ntpshmread.c
parentc4335532ee6cc4aaa7d9074f1621496a86a021ae (diff)
downloadgpsd-718b4c4d7559f879cfa90a451133890988f18669.tar.gz
clock_gettime() port fix for OS X.
Diffstat (limited to 'ntpshmread.c')
-rw-r--r--ntpshmread.c11
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) {