|
Lines 1-64
Link Here
|
| 1 |
From 12837594b705ad10fdadfd0ba1bfc2249b3b1264 Mon Sep 17 00:00:00 2001 |
|
|
| 2 |
From: Michael Krelin <hacker@klever.net> |
| 3 |
Date: Sun, 29 Jun 2008 16:08:01 +0000 |
| 4 |
Subject: Fixed w3c to unix timestamp conversion for FreeBSD |
| 5 |
|
| 6 |
Thanks to Göran Löwkrantz for pointing both to the problem and possible |
| 7 |
solution. |
| 8 |
|
| 9 |
Signed-off-by: Michael Krelin <hacker@klever.net> |
| 10 |
--- |
| 11 |
diff --git a/configure.ac b/configure.ac |
| 12 |
index 3194718..3484146 100644 |
| 13 |
--- configure.ac |
| 14 |
+++ configure.ac |
| 15 |
@@ -10,6 +10,7 @@ AC_PROG_LIBTOOL |
| 16 |
PKG_PROG_PKG_CONFIG |
| 17 |
|
| 18 |
AC_HEADER_STDC |
| 19 |
+AC_CHECK_FUNCS([timegm]) |
| 20 |
|
| 21 |
AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) |
| 22 |
|
| 23 |
diff --git a/lib/util.cc b/lib/util.cc |
| 24 |
index d979502..a46ba2a 100644 |
| 25 |
--- lib/util.cc |
| 26 |
+++ lib/util.cc |
| 27 |
@@ -122,6 +122,21 @@ namespace opkele { |
| 28 |
return rv; |
| 29 |
} |
| 30 |
|
| 31 |
+#ifndef HAVE_TIMEGM |
| 32 |
+ static time_t timegm(struct tm *t) { |
| 33 |
+ char *tz = getenv("TZ"); |
| 34 |
+ setenv("TZ","",1); tzset(); |
| 35 |
+ time_t rv = mktime(t); |
| 36 |
+ if(tz) |
| 37 |
+ setenv("TZ",tz,1); |
| 38 |
+ else |
| 39 |
+ unsetenv("TZ"); |
| 40 |
+ tzset(); |
| 41 |
+ return rv; |
| 42 |
+ } |
| 43 |
+# define timegm opkele::util::timegm |
| 44 |
+#endif /* HAVE_TIMEGM */ |
| 45 |
+ |
| 46 |
time_t w3c_to_time(const string& w) { |
| 47 |
int fraction; |
| 48 |
struct tm tm_t; |
| 49 |
@@ -145,10 +160,10 @@ namespace opkele { |
| 50 |
throw failed_conversion(OPKELE_CP_ "failed to sscanf()"); |
| 51 |
tm_t.tm_mon--; |
| 52 |
tm_t.tm_year-=1900; |
| 53 |
- time_t rv = mktime(&tm_t); |
| 54 |
+ time_t rv = timegm(&tm_t); |
| 55 |
if(rv==(time_t)-1) |
| 56 |
- throw failed_conversion(OPKELE_CP_ "failed to mktime()"); |
| 57 |
- return rv-timezone; |
| 58 |
+ throw failed_conversion(OPKELE_CP_ "failed to gmtime()"); |
| 59 |
+ return rv; |
| 60 |
} |
| 61 |
|
| 62 |
/* |
| 63 |
-- |
| 64 |
cgit v0.7.1-118-g42ef |