From c1ba7516b8dcb00c658d2630c2a8be9f4355e618 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 25 Sep 2014 16:55:10 -0400 Subject: Remove some custom code, at the cost of introducing a glibc depenency. Dependency soon to be fixed. All regression tests pass. --- driver_garmin_txt.c | 2 +- driver_sirf.c | 4 ++-- driver_zodiac.c | 2 +- gps.h | 1 - gpsutils.c | 30 +----------------------------- test_mkgmtime.c | 2 +- timebase.c | 2 +- 7 files changed, 7 insertions(+), 36 deletions(-) diff --git a/driver_garmin_txt.c b/driver_garmin_txt.c index 5d249909..ad69578c 100644 --- a/driver_garmin_txt.c +++ b/driver_garmin_txt.c @@ -322,7 +322,7 @@ gps_mask_t garmintxt_parse(struct gps_device_t * session) session->driver.garmintxt.date.tm_sec = (int)result; session->driver.garmintxt.subseconds = 0; session->newdata.time = - (timestamp_t)mkgmtime(&session->driver.garmintxt.date) + + (timestamp_t)timegm(&session->driver.garmintxt.date) + session->driver.garmintxt.subseconds; mask |= TIME_SET; } while (0); diff --git a/driver_sirf.c b/driver_sirf.c index 684c306b..cd81b8a4 100644 --- a/driver_sirf.c +++ b/driver_sirf.c @@ -1016,7 +1016,7 @@ static gps_mask_t sirf_msg_ublox(struct gps_device_t *session, unpacked_date.tm_sec = 0; subseconds = ((unsigned short)getbeu16(buf, 32)) * 1e-3; /*@ -compdef */ - session->newdata.time = (timestamp_t)mkgmtime(&unpacked_date) + subseconds; + session->newdata.time = (timestamp_t)timegm(&unpacked_date) + subseconds; /*@ +compdef */ #ifdef TIMEHINT_ENABLE if (0 == (session->driver.sirf.time_seen & TIME_SEEN_UTC_2)) { @@ -1069,7 +1069,7 @@ static gps_mask_t sirf_msg_ppstime(struct gps_device_t *session, unpacked_date.tm_mon = (int)getub(buf, 5) - 1; unpacked_date.tm_year = (int)getbeu16(buf, 6) - 1900; /*@ -compdef */ - session->newdata.time = (timestamp_t)mkgmtime(&unpacked_date); + session->newdata.time = (timestamp_t)timegm(&unpacked_date); /*@ +compdef */ session->context->leap_seconds = (int)getbeu16(buf, 8); session->context->valid |= LEAP_SECOND_VALID; diff --git a/driver_zodiac.c b/driver_zodiac.c index 6ff24efe..c961a963 100644 --- a/driver_zodiac.c +++ b/driver_zodiac.c @@ -167,7 +167,7 @@ static gps_mask_t handle1000(struct gps_device_t *session) unpacked_date.tm_sec = (int)getzword(24); subseconds = (int)getzlong(25) / 1e9; /*@ -compdef */ - session->newdata.time = (timestamp_t)mkgmtime(&unpacked_date) + subseconds; + session->newdata.time = (timestamp_t)timegm(&unpacked_date) + subseconds; /*@ +compdef */ /*@ -type @*/ session->newdata.latitude = ((long)getzlong(27)) * RAD_2_DEG * 1e-8; diff --git a/gps.h b/gps.h index 16955bc3..29e0d291 100644 --- a/gps.h +++ b/gps.h @@ -2052,7 +2052,6 @@ extern void gps_enable_debug(int, FILE *); extern /*@observer@*/const char *gps_maskdump(gps_mask_t); extern double safe_atof(const char *); -extern time_t mkgmtime(register struct tm *); extern timestamp_t timestamp(void); extern timestamp_t iso8601_to_unix(char *); extern /*@observer@*/char *unix_to_iso8601(timestamp_t t, /*@ out @*/char[], size_t len); diff --git a/gpsutils.c b/gpsutils.c index dfcaa3f9..ab03ecd5 100644 --- a/gpsutils.c +++ b/gpsutils.c @@ -308,34 +308,6 @@ timestamp_t timestamp(void) #endif } -time_t mkgmtime(register struct tm * t) -/* struct tm to seconds since Unix epoch */ -{ - register int year; - register time_t result; - static const int cumdays[MONTHSPERYEAR] = - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; - - /*@ +matchanyintegral @*/ - year = 1900 + t->tm_year + t->tm_mon / MONTHSPERYEAR; - result = (year - 1970) * 365 + cumdays[t->tm_mon % MONTHSPERYEAR]; - result += (year - 1968) / 4; - result -= (year - 1900) / 100; - result += (year - 1600) / 400; - if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0) && - (t->tm_mon % MONTHSPERYEAR) < 2) - result--; - result += t->tm_mday - 1; - result *= 24; - result += t->tm_hour; - result *= 60; - result += t->tm_min; - result *= 60; - result += t->tm_sec; - /*@ -matchanyintegral @*/ - return (result); -} - timestamp_t iso8601_to_unix( /*@in@*/ char *isotime) /* ISO8601 UTC to Unix UTC */ { @@ -349,7 +321,7 @@ timestamp_t iso8601_to_unix( /*@in@*/ char *isotime) usec = strtod(dp, NULL); else usec = 0; - return (timestamp_t)mkgmtime(&tm) + usec; + return (timestamp_t)timegm(&tm) + usec; #else double usec = 0; diff --git a/test_mkgmtime.c b/test_mkgmtime.c index 8235e24d..df394e99 100644 --- a/test_mkgmtime.c +++ b/test_mkgmtime.c @@ -97,7 +97,7 @@ int main(int argc UNUSED, char *argv[] UNUSED) #if 0 /* use this to calculate with glibc */ ts = mktime(&tests[i].t); #else - ts = mkgmtime(&tests[i].t); + ts = timegm(&tests[i].t); #endif if (ts != tests[i].result) { failed = true; diff --git a/timebase.c b/timebase.c index 7c790c06..2aff11cc 100644 --- a/timebase.c +++ b/timebase.c @@ -272,7 +272,7 @@ timestamp_t gpsd_utc_resolve(/*@in@*/struct gps_device_t *session) */ timestamp_t t; - t = (timestamp_t)mkgmtime(&session->nmea.date) + + t = (timestamp_t)timegm(&session->nmea.date) + session->nmea.subseconds; session->context->valid &=~ GPS_TIME_VALID; -- cgit v1.2.1