From 0deeeb2b1fb55d78c4abedbf88c8f46d9b300ed6 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 8 Mar 2015 10:42:04 -0400 Subject: Break timespec_str out of gpsutils.c. It's not used on the client side, and it's needed separately for ntplib. All regression tesrs pass. PPS is live. --- SConstruct | 1 + gpsd.h-tail | 3 --- gpsutils.c | 30 +----------------------------- ppsthread.c | 1 + timehint.c | 1 + timespec_str.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ timespec_str.h | 15 +++++++++++++++ 7 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 timespec_str.c create mode 100644 timespec_str.h diff --git a/SConstruct b/SConstruct index 8e9c89f4..db0befde 100644 --- a/SConstruct +++ b/SConstruct @@ -866,6 +866,7 @@ libgpsd_sources = [ "serial.c", "subframe.c", "timebase.c", + "timespec_str.c", "drivers.c", "driver_ais.c", "driver_evermore.c", diff --git a/gpsd.h-tail b/gpsd.h-tail index 413986ec..83fd6c18 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -922,9 +922,6 @@ extern void ntpshm_link_activate(struct gps_device_t *); * is tv_sec > 2, then inevitable loss of precision in tv_nsec */ #define TSTONS(ts) ((double)((ts)->tv_sec + ((ts)->tv_nsec / 1e9))) -extern void timespec_str(const struct timespec *, /*@out@*/char *, int); -#define TIMESPEC_LEN 22 /* required length of a timespec buffer */ - extern void errout_reset(struct gpsd_errout_t *errout); extern void gpsd_acquire_reporting_lock(void); diff --git a/gpsutils.c b/gpsutils.c index e7000f70..ea5c45bb 100644 --- a/gpsutils.c +++ b/gpsutils.c @@ -479,32 +479,4 @@ double earth_distance(double lat1, double lon1, double lat2, double lon2) return earth_distance_and_bearings(lat1, lon1, lat2, lon2, NULL, NULL); } -/* Convert a normailized timespec to a nice string - * put in it *buf, buf should be at least 22 bytes - * - * the returned buffer will look like, shortest case: - * sign character ' ' or '-' - * one digit of seconds - * decmal point '.' - * 9 digits of nanoSec - * - * So 12 chars, like this: "-0.123456789" - * - * Absolute worst case is 10 digits of seconds. - * So 21 digits like this: "-2147483647.123456789" - * -*/ -void timespec_str(const struct timespec *ts, /*@out@*/char *buf, int buf_size) -{ - char sign = ' '; - - /*@-type@*//* splint is confused about timespec*/ - if ( (0 > ts->tv_nsec ) || ( 0 > ts->tv_sec ) ) { - sign = '-'; - } - (void) snprintf( buf, buf_size, "%c%ld.%09ld", - sign, - (long)labs(ts->tv_sec), - (long)labs(ts->tv_nsec)); - /*@+type@*/ -} +/* end */ diff --git a/ppsthread.c b/ppsthread.c index ccc0f2bf..0edf9ecb 100644 --- a/ppsthread.c +++ b/ppsthread.c @@ -56,6 +56,7 @@ #include #endif /* S_SPLINT_S */ +#include "timespec_str.h" #include "gpsd.h" #ifdef PPS_ENABLE diff --git a/timehint.c b/timehint.c index 8a6f9cf4..5f17e333 100644 --- a/timehint.c +++ b/timehint.c @@ -21,6 +21,7 @@ #include #endif /* S_SPLINT_S */ +#include "timespec_str.h" #include "gpsd.h" #ifdef NTPSHM_ENABLE diff --git a/timespec_str.c b/timespec_str.c new file mode 100644 index 00000000..69e045ee --- /dev/null +++ b/timespec_str.c @@ -0,0 +1,54 @@ +/* + * This file is Copyright (c) 2010 by the GPSD project + * BSD terms apply: see the file COPYING in the distribution root for details. + */ + +/* + * We also need to set the value high enough to signal inclusion of + * newer features (like clock_gettime). See the POSIX spec for more info: + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_01_02 +*/ +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "timespec_str.h" + +/* Convert a normalized timespec to a nice string + * put in it *buf, buf should be at least 22 bytes + * + * the returned buffer will look like, shortest case: + * sign character ' ' or '-' + * one digit of seconds + * decmal point '.' + * 9 digits of nanoSec + * + * So 12 chars, like this: "-0.123456789" + * + * Absolute worst case is 10 digits of seconds. + * So 21 digits like this: "-2147483647.123456789" + * +*/ +void timespec_str(const struct timespec *ts, /*@out@*/char *buf, int buf_size) +{ + char sign = ' '; + + /*@-type@*//* splint is confused about timespec*/ + if ( (0 > ts->tv_nsec ) || ( 0 > ts->tv_sec ) ) { + sign = '-'; + } + (void) snprintf( buf, buf_size, "%c%ld.%09ld", + sign, + (long)labs(ts->tv_sec), + (long)labs(ts->tv_nsec)); + /*@+type@*/ +} + +/* end */ diff --git a/timespec_str.h b/timespec_str.h new file mode 100644 index 00000000..b644c7d0 --- /dev/null +++ b/timespec_str.h @@ -0,0 +1,15 @@ +/* + * This file is Copyright (c) 2015 by the GPSD project + * BSD terms apply: see the file COPYING in the distribution root for details. + */ + +#ifndef GPSD_TIMESPEC_H +#define GPSD_TIMESPEC_H + +#define TIMESPEC_LEN 22 /* required length of a timespec buffer */ + +extern void timespec_str(const struct timespec *, /*@out@*/char *, int); + +#endif /* GPSD_TIMESPEC_H */ + +/* end */ -- cgit v1.2.1