aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2014-04-16 21:11:13 +0200
committerDaniel Willmann <daniel@totalueberwachung.de>2014-04-16 21:43:33 +0200
commit78f049142fffbcbb0b5e857f597269dbdaceac7c (patch)
treedb20f4ad7034fcef73f6cc5fdc06e1e05d3058f0
parent7d3258046cef22ffbdf14237ce7ca33b74bc0170 (diff)
Check if timegm is available and try to be as correct as possible if notdaniel/scts-fixes
-rw-r--r--configure.ac25
-rw-r--r--src/gsm/gsm0411_utils.c12
2 files changed, 35 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index fbc83f3..f8a7bf7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,6 +51,31 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
CFLAGS="$saved_CFLAGS"
AC_SUBST(SYMBOL_VISIBILITY)
+AC_DEFUN([CHECK_HAVE_TIMEGM], [
+ AC_CACHE_CHECK(
+ [whether timegm function is present],
+ osmo_cv_have_timegm,
+ [AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([
+ #include <time.h>
+ ], [
+ time_t t = time(NULL);
+ struct tm* lt = gmtime(&t);
+ t = timegm(lt);
+ ])
+ ],
+ osmo_cv_have_timegm=yes,
+ osmo_cv_have_timegm=no
+ )]
+ )
+ if test "x$osmo_cv_have_timegm" = xyes; then
+ AC_DEFINE(HAVE_TIMEGM, 1,
+ [Define if timegm function is present.])
+ fi
+])
+
+CHECK_HAVE_TIMEGM
+
AC_DEFUN([CHECK_TM_INCLUDES_TM_GMTOFF], [
AC_CACHE_CHECK(
[whether struct tm has tm_gmtoff member],
diff --git a/src/gsm/gsm0411_utils.c b/src/gsm/gsm0411_utils.c
index 0dd5ff8..0e87f51 100644
--- a/src/gsm/gsm0411_utils.c
+++ b/src/gsm/gsm0411_utils.c
@@ -150,11 +150,19 @@ time_t gsm340_scts(uint8_t *scts)
if (tz&0x08)
ofs_min = -ofs_min;
- /* Take into account timezone offset, timegm() can deal with
+ /* Take into account timezone offset from SCTS, timegm() can deal with
* values outside of the [0, 59] range */
tm.tm_min -= ofs_min;
-
+#ifdef HAVE_TIMEGM
timestamp = timegm(&tm);
+#else
+#warning gsm340_scts() without timegm() assumes that DST offset is one hour
+ tm.tm_isdst = 0;
+ timestamp = mktime(&tm);
+ timestamp += time_gmtoff(timestamp);
+ if (tm.tm_isdst)
+ timestamp -= 3600;
+#endif
if (timestamp < 0)
return -1;