From 9c3dc90d16a40789081c84e46620f4d66689fec1 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 8 Apr 2012 16:59:24 +0200 Subject: [PATCH] introduce HAVE_TM_GMTOFF_IN_TM Not all architectures have the tm.tm_gmtoff member. This fixes cygwin builds. --- openbsc/configure.ac | 24 ++++++++++++++++++++++++ openbsc/src/libmsc/gsm_04_08.c | 7 +++++++ openbsc/src/libmsc/gsm_04_11.c | 9 +++++++++ 3 files changed, 40 insertions(+) diff --git a/openbsc/configure.ac b/openbsc/configure.ac index 56e4b60ad..16eb732b6 100644 --- a/openbsc/configure.ac +++ b/openbsc/configure.ac @@ -83,6 +83,30 @@ if test "$enable_coverage" = "yes"; then AC_SUBST([COVERAGE_LDFLAGS]) fi +AC_DEFUN([CHECK_TM_INCLUDES_TM_GMTOFF], [ + AC_CACHE_CHECK( + [whether struct tm has tm_gmtoff member], + osmo_cv_tm_includes_tm_gmtoff, + [AC_LINK_IFELSE([ + AC_LANG_PROGRAM([ + #include + ], [ + time_t t = time(NULL); + struct tm* lt = localtime(&t); + int off = lt->tm_gmtoff; + ]) + ], + osmo_cv_tm_includes_tm_gmtoff=yes, + osmo_cv_tm_includes_tm_gmtoff=no + )] + ) + if test "x$osmo_cv_tm_includes_tm_gmtoff" = xyes; then + AC_DEFINE(HAVE_TM_GMTOFF_IN_TM, 1, + [Define if struct tm has tm_gmtoff member.]) + fi +]) + +CHECK_TM_INCLUDES_TM_GMTOFF dnl Generate the output AM_CONFIG_HEADER(bscconfig.h) diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c index 20a2cc502..e596b210d 100644 --- a/openbsc/src/libmsc/gsm_04_08.c +++ b/openbsc/src/libmsc/gsm_04_08.c @@ -29,6 +29,8 @@ #include #include +#include "bscconfig.h" + #include #include #include @@ -734,7 +736,12 @@ int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn) /* Need to get GSM offset and convert into 15 min units */ /* This probably breaks if gmtoff returns a value not evenly divisible by 15? */ local_time = localtime(&cur_t); +#ifdef HAVE_TM_GMTOFF_IN_TM tzunits = (local_time->tm_gmtoff/60)/15; +#else +#warning find a portable way to obtain the timezone offset + tzunits = 0; +#endif if (tzunits < 0) { tzunits = tzunits/-1; ptr8[7] = bcdify(tzunits); diff --git a/openbsc/src/libmsc/gsm_04_11.c b/openbsc/src/libmsc/gsm_04_11.c index ee7f5772c..76c37208b 100644 --- a/openbsc/src/libmsc/gsm_04_11.c +++ b/openbsc/src/libmsc/gsm_04_11.c @@ -32,6 +32,8 @@ #include #include +#include "bscconfig.h" + #include #include #include @@ -279,7 +281,12 @@ static void gsm340_gen_scts(uint8_t *scts, time_t time) *scts++ = bcdify(tm->tm_hour); *scts++ = bcdify(tm->tm_min); *scts++ = bcdify(tm->tm_sec); +#ifdef HAVE_TM_GMTOFF_IN_TM *scts++ = bcdify(tm->tm_gmtoff/(60*15)); +#else +#warning find a portable way to obtain timezone offset + *scts++ = 0; +#endif } /* Decode 03.40 TP-SCTS (into utc/gmt timestamp) */ @@ -300,7 +307,9 @@ static time_t gsm340_scts(uint8_t *scts) tm.tm_sec = unbcdify(*scts++); /* according to gsm 03.40 time zone is "expressed in quarters of an hour" */ +#ifdef HAVE_TM_GMTOFF_IN_TM tm.tm_gmtoff = unbcdify(*scts++) * 15*60; +#endif return mktime(&tm); }