libosmogsm: Back-port SMS related fixes from openbsc

This was fixed in 9c3dc90d16a40789081c84e46620f4d66689fec1 of
openbsc.git, after the sms code had been migrated here:
    introduce HAVE_TM_GMTOFF_IN_TM

    Not all architectures have the tm.tm_gmtoff member.  This fixes cygwin builds.
This commit is contained in:
Harald Welte 2012-08-29 16:47:30 +02:00
parent b5372ab110
commit 7c8e2cc7ac
2 changed files with 35 additions and 1 deletions

View File

@ -39,6 +39,31 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
CFLAGS="$saved_CFLAGS"
AC_SUBST(SYMBOL_VISIBILITY)
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.h>
], [
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(config.h)

View File

@ -25,6 +25,7 @@
*
*/
#include "../../config.h"
#include <time.h>
#include <string.h>
@ -80,7 +81,12 @@ void gsm340_gen_scts(uint8_t *scts, time_t time)
*scts++ = gsm411_bcdify(tm->tm_hour);
*scts++ = gsm411_bcdify(tm->tm_min);
*scts++ = gsm411_bcdify(tm->tm_sec);
*scts++ = gsm411_bcdify(0); /* GMT */
#ifdef HAVE_TM_GMTOFF_IN_TM
*scts++ = gsm411_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) */
@ -101,6 +107,9 @@ time_t gsm340_scts(uint8_t *scts)
tm.tm_hour = gsm411_unbcdify(*scts++);
tm.tm_min = gsm411_unbcdify(*scts++);
tm.tm_sec = gsm411_unbcdify(*scts++);
#ifdef HAVE_TM_GMTOFF_IN_TM
tm.tm_gmtoff = gsm411_unbcdify(*scts++) * 15*60;
#endif
/* according to gsm 03.40 time zone is
"expressed in quarters of an hour" */