summaryrefslogtreecommitdiff
path: root/gpsd.h-tail
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2015-02-11 19:11:06 -0800
committerGary E. Miller <gem@rellim.com>2015-02-11 19:11:06 -0800
commitc988130851015de651b2632a1f4068c7c3661c1e (patch)
treee7e27511dc49b2db2d4354a25e60866e4d1c6e74 /gpsd.h-tail
parent15898d8744c48b35dd0a4baebb94a6ffd155346e (diff)
downloadgpsd-c988130851015de651b2632a1f4068c7c3661c1e.tar.gz
Keeping TS_NORM() a macro too ugly, convert to inline function
Diffstat (limited to 'gpsd.h-tail')
-rw-r--r--gpsd.h-tail45
1 files changed, 25 insertions, 20 deletions
diff --git a/gpsd.h-tail b/gpsd.h-tail
index 65f7b7de..6436f0bc 100644
--- a/gpsd.h-tail
+++ b/gpsd.h-tail
@@ -884,26 +884,31 @@ extern void pps_early_init(struct gps_context_t *);
#endif /* PPS_ENABLE */
/* normalize a timespec */
-#define TS_NORM(ts) \
- do { \
- if ( 1 > (ts)->tv_sec ) { \
- if ( -1000000000 >= (ts)->tv_nsec ) { \
- (ts)->tv_nsec += 1000000000; \
- (ts)->tv_sec--; \
- } else if ( 0 < (ts)->tv_nsec ) { \
- (ts)->tv_nsec -= 1000000000; \
- (ts)->tv_sec++; \
- } \
- } else { \
- if ( 1000000000 <= (ts)->tv_nsec ) { \
- (ts)->tv_nsec -= 1000000000; \
- (ts)->tv_sec++; \
- } else if ( 0 > (ts)->tv_nsec ) { \
- (ts)->tv_nsec += 1000000000; \
- (ts)->tv_sec--; \
- } \
- } \
- } while (0)
+static inline void TS_NORM( struct timespec *ts)
+{
+ if ( ( 1 <= ts->tv_sec ) ||
+ ( (0 == ts->tv_sec ) && (0 <= ts->tv_nsec ) ) ) {
+ /* result is positive */
+ if ( 1000000000 <= ts->tv_nsec ) {
+ /* borrow from tv_sec */
+ ts->tv_nsec -= 1000000000;
+ ts->tv_sec++;
+ } else if ( 0 > (ts)->tv_nsec ) {
+ /* carry from tv_sec */
+ ts->tv_nsec += 1000000000;
+ ts->tv_sec--;
+ }
+ } else {
+ /* result is negative */
+ if ( -1000000000 >= ts->tv_nsec ) {
+ ts->tv_nsec += 1000000000;
+ ts->tv_sec--;
+ } else if ( 0 < ts->tv_nsec ) {
+ ts->tv_nsec -= 1000000000;
+ ts->tv_sec++;
+ }
+ }
+}
/* normalize a timeval */
#define TV_NORM(tv) \