mirror of https://gerrit.osmocom.org/libosmocore
Check if timegm is available and try to be as correct as possible if not
This commit is contained in:
parent
7d3258046c
commit
78f049142f
25
configure.ac
25
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],
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue