summaryrefslogtreecommitdiff
path: root/gpsutils.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2014-09-29 15:39:19 -0400
committerEric S. Raymond <esr@thyrsus.com>2014-09-29 15:39:19 -0400
commit76118dd9a35eb1516aee287d3aaa8f3824a712fb (patch)
tree65403bab9b535e2922342e527d732cb9fd8ff032 /gpsutils.c
parent0a36cb1944a53cb206161997da44486d7c95e712 (diff)
downloadgpsd-76118dd9a35eb1516aee287d3aaa8f3824a712fb.tar.gz
Better way to avoid glibc dependency.
Returns us to something amost identical to the original code. Sigh. Timezones are a swamp. All regression tests pass.
Diffstat (limited to 'gpsutils.c')
-rw-r--r--gpsutils.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/gpsutils.c b/gpsutils.c
index 6b72776f..b02975fe 100644
--- a/gpsutils.c
+++ b/gpsutils.c
@@ -308,6 +308,36 @@ 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;
+ if (t->tm_isdst == 1)
+ result -= 3600;
+ /*@ -matchanyintegral @*/
+ return (result);
+}
+
timestamp_t iso8601_to_unix( /*@in@*/ char *isotime)
/* ISO8601 UTC to Unix UTC */
{