-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | lib/util.cc | 21 |
2 files changed, 19 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index 3194718..3484146 100644 --- a/configure.ac +++ b/configure.ac @@ -5,16 +5,17 @@ AM_INIT_AUTOMAKE([dist-bzip2]) AC_PROG_INSTALL AC_PROG_CXX AC_PROG_CC AC_PROG_LIBTOOL PKG_PROG_PKG_CONFIG AC_HEADER_STDC +AC_CHECK_FUNCS([timegm]) AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) AC_MSG_CHECKING([for source tree version]) if headrev=$(cd $srcdir && git rev-parse --verify HEAD 2>/dev/null) ; then PACKAGE_SRC_VERSION="$(cd $srcdir && git describe --tags $headrev)" test "$PACKAGE_SRC_VERSION" = "$PACKAGE_VERSION" \ -o "${PACKAGE_SRC_VERSION#${PACKAGE_VERSION}-}" != "$PACKAGE_SRC_VERSION" || PACKAGE_SRC_VERSION="${PACKAGE_VERSION}:${PACKAGE_SRC_VERSION}" diff --git a/lib/util.cc b/lib/util.cc index d979502..a46ba2a 100644 --- a/lib/util.cc +++ b/lib/util.cc @@ -117,16 +117,31 @@ namespace opkele { if(!gmtime_r(&t,&tm_t)) throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()"); char rv[25]; if(!strftime(rv,sizeof(rv)-1,"%Y-%m-%dT%H:%M:%SZ",&tm_t)) throw failed_conversion(OPKELE_CP_ "failed to strftime()"); return rv; } +#ifndef HAVE_TIMEGM + static time_t timegm(struct tm *t) { + char *tz = getenv("TZ"); + setenv("TZ","",1); tzset(); + time_t rv = mktime(t); + if(tz) + setenv("TZ",tz,1); + else + unsetenv("TZ"); + tzset(); + return rv; + } +# define timegm opkele::util::timegm +#endif /* HAVE_TIMEGM */ + time_t w3c_to_time(const string& w) { int fraction; struct tm tm_t; memset(&tm_t,0,sizeof(tm_t)); if( ( sscanf( w.c_str(), "%04d-%02d-%02dT%02d:%02d:%02dZ", @@ -140,20 +155,20 @@ namespace opkele { &tm_t.tm_year,&tm_t.tm_mon,&tm_t.tm_mday, &tm_t.tm_hour,&tm_t.tm_min,&tm_t.tm_sec, &fraction ) != 7 ) ) throw failed_conversion(OPKELE_CP_ "failed to sscanf()"); tm_t.tm_mon--; tm_t.tm_year-=1900; - time_t rv = mktime(&tm_t); + time_t rv = timegm(&tm_t); if(rv==(time_t)-1) - throw failed_conversion(OPKELE_CP_ "failed to mktime()"); - return rv-timezone; + throw failed_conversion(OPKELE_CP_ "failed to gmtime()"); + return rv; } /* * */ static inline bool isrfc3986unreserved(int c) { if(c<'-') return false; |