author | Michael Krelin <hacker@klever.net> | 2008-06-29 16:08:01 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-06-29 16:11:44 (UTC) |
commit | 12837594b705ad10fdadfd0ba1bfc2249b3b1264 (patch) (unidiff) | |
tree | e0502e678b09668ec59828237ebf5972014d0ce0 | |
parent | 362678728b8232c9490e14ba14ff323d9a92d6be (diff) | |
download | libopkele-12837594b705ad10fdadfd0ba1bfc2249b3b1264.zip libopkele-12837594b705ad10fdadfd0ba1bfc2249b3b1264.tar.gz libopkele-12837594b705ad10fdadfd0ba1bfc2249b3b1264.tar.bz2 |
Fixed w3c to unix timestamp conversion for FreeBSD
Thanks to Göran Löwkrantz for pointing both to the problem and possible
solution.
Signed-off-by: Michael Krelin <hacker@klever.net>
-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 | |||
@@ -12,2 +12,3 @@ PKG_PROG_PKG_CONFIG | |||
12 | AC_HEADER_STDC | 12 | AC_HEADER_STDC |
13 | AC_CHECK_FUNCS([timegm]) | ||
13 | 14 | ||
diff --git a/lib/util.cc b/lib/util.cc index d979502..a46ba2a 100644 --- a/lib/util.cc +++ b/lib/util.cc | |||
@@ -124,2 +124,17 @@ namespace opkele { | |||
124 | 124 | ||
125 | #ifndef HAVE_TIMEGM | ||
126 | static time_t timegm(struct tm *t) { | ||
127 | char *tz = getenv("TZ"); | ||
128 | setenv("TZ","",1); tzset(); | ||
129 | time_t rv = mktime(t); | ||
130 | if(tz) | ||
131 | setenv("TZ",tz,1); | ||
132 | else | ||
133 | unsetenv("TZ"); | ||
134 | tzset(); | ||
135 | return rv; | ||
136 | } | ||
137 | #define timegm opkele::util::timegm | ||
138 | #endif /* HAVE_TIMEGM */ | ||
139 | |||
125 | time_t w3c_to_time(const string& w) { | 140 | time_t w3c_to_time(const string& w) { |
@@ -147,6 +162,6 @@ namespace opkele { | |||
147 | tm_t.tm_year-=1900; | 162 | tm_t.tm_year-=1900; |
148 | time_t rv = mktime(&tm_t); | 163 | time_t rv = timegm(&tm_t); |
149 | if(rv==(time_t)-1) | 164 | if(rv==(time_t)-1) |
150 | throw failed_conversion(OPKELE_CP_ "failed to mktime()"); | 165 | throw failed_conversion(OPKELE_CP_ "failed to gmtime()"); |
151 | return rv-timezone; | 166 | return rv; |
152 | } | 167 | } |