From 78f049142fffbcbb0b5e857f597269dbdaceac7c Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Wed, 16 Apr 2014 21:11:13 +0200 Subject: Check if timegm is available and try to be as correct as possible if not --- configure.ac | 25 +++++++++++++++++++++++++ src/gsm/gsm0411_utils.c | 12 ++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index fbc83f39..f8a7bf75 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_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 0dd5ff84..0e87f515 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; -- cgit v1.2.3