diff options
author | Gary E. Miller <gem@rellim.com> | 2015-02-24 13:19:56 -0800 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2015-02-24 13:19:56 -0800 |
commit | d54442d7d438677c3faac1f826d0c0bb1e9a2988 (patch) | |
tree | ee68bfe69ab5bd23fc924b642af510d692fa40ad /gpsmon.c | |
parent | 5a98a16337964c3496ca1cd9e61904121d96a01e (diff) | |
download | gpsd-d54442d7d438677c3faac1f826d0c0bb1e9a2988.tar.gz |
Convert gpsmon_hook() to use timespec_str()
timespec_str() there fixes problems displaying negative timespecs
Diffstat (limited to 'gpsmon.c')
-rw-r--r-- | gpsmon.c | 27 |
1 files changed, 17 insertions, 10 deletions
@@ -754,18 +754,25 @@ static void gpsmon_hook(struct gps_device_t *device, gps_mask_t changed UNUSED) } else { /*@-type -noeffect@*/ /* splint is confused about struct timespec */ struct timespec timedelta; - TS_SUB( &timedelta, &noclobber.pps.real, - &noclobber.pps.clock); + char pps_clock_str[TIMESPEC_LEN]; + char pps_real_str[TIMESPEC_LEN]; + char timedelta_str[TIMESPEC_LEN]; + + TS_SUB( &timedelta, &noclobber.pps.real, &noclobber.pps.clock); + + if (!curses_active) { + timespec_str( &noclobber.pps.clock, pps_clock_str, + sizeof(pps_clock_str) ); + timespec_str( &noclobber.pps.real, pps_real_str, + sizeof(pps_real_str) ); + timespec_str( &timedelta, timedelta_str, sizeof(timedelta_str) ); - if (!curses_active) (void)fprintf(stderr, - "PPS=%ld.%09ld clock=%ld.%09ld offset=%ld.%09ld\n", - (long)noclobber.pps.clock.tv_sec, - (long)noclobber.pps.clock.tv_nsec, - (long)noclobber.pps.real.tv_sec, - (long)noclobber.pps.real.tv_nsec, - (long)timedelta.tv_sec, - (long)timedelta.tv_nsec); + "PPS=%.20s clock=%.20s offset=%.20s\n", + pps_clock_str, + pps_real_str, + timedelta_str); + } /*@+type +noeffect@*/ (void)strlcpy(buf, PPSBAR, sizeof(buf)); |