From 0e120c4bdbfd309ec8a5bbd4005d82edd7700bd3 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 2 Mar 2015 00:16:51 -0500 Subject: Complete port of clock_gettime(3) and teach gpsipe to use it. This eliminates the last gettimeofday(3) from the code. POSIX.1-2008 marked it obsolete. All regression tests pass. --- gpspipe.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'gpspipe.c') diff --git a/gpspipe.c b/gpspipe.c index 66d9c197..6de59b2c 100644 --- a/gpspipe.c +++ b/gpspipe.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -43,6 +42,8 @@ #endif /* S_SPLINT_S */ #include "gpsd.h" + +#include "gpsd_config.h" #include "gpsdclient.h" #include "revision.h" @@ -333,10 +334,10 @@ int main(int argc, char **argv) } if (new_line && timestamp) { char tmstr_u[20]; // time with "usec" resolution - struct timeval now; + struct timespec now; struct tm *tmp_now; - (void)gettimeofday( &now, NULL ); + (void)clock_gettime(CLOCK_REALTIME, &now); tmp_now = localtime((time_t *)&(now.tv_sec)); (void)strftime(tmstr, sizeof(tmstr), format, tmp_now); new_line = 0; @@ -346,11 +347,11 @@ int main(int argc, char **argv) (void)snprintf(tmstr_u, sizeof(tmstr_u), " %ld.%06ld", (long)now.tv_sec, - (long)now.tv_usec); + (long)now.tv_nsec/1000); break; case 1: (void)snprintf(tmstr_u, sizeof(tmstr_u), - ".%06ld", (long)now.tv_usec); + ".%06ld", (long)now.tv_nsec/1000); break; default: *tmstr_u = '\0'; -- cgit v1.2.1