[Xfce4-commits] <xfce4-weather-plugin:master> Revert "Replace my_timegm() with something that doesn't lock up."
Harald Judt
noreply at xfce.org
Thu Aug 2 23:08:01 CEST 2012
Updating branch refs/heads/master
to 4c4e976788f1680bd25cb1393b6f145eb0162dfd (commit)
from de7c22ff59bc2b98463122f7362bbcde0711a359 (commit)
commit 4c4e976788f1680bd25cb1393b6f145eb0162dfd
Author: Harald Judt <h.judt at gmx.at>
Date: Wed Aug 1 20:25:20 2012 +0200
Revert "Replace my_timegm() with something that doesn't lock up."
This reverts commit c5e86912a6661c6a7b04d66c786693a01a2d45ea.
It seems that the man page my_timegm worked fine, and the problem
occurred from a double-free error fixed in d2496aeae3c2d56
"Fix double free when parsing xml_time."
So replacing my_timegm was unnecessary, though it helped a bit in
tracking the problem down.
panel-plugin/weather-parsers.c | 50 +++++++++++++--------------------------
1 files changed, 17 insertions(+), 33 deletions(-)
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index f7c2438..b8fbf62 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -34,42 +34,25 @@
/*
- * Portable? replacement for the deprecated GNU timegm() only
- * available on Linux and BSDs. The one recommended by the (Linux!)
- * man page does not work correctly, it seems threads get stuck in
- * setenv(TZ).
- * This one is from http://lists.debian.org/deity/2002/04/msg00082.html
- * and seems to be rather uncomplicated compared to other solutions.
- * One problem with it is that it does calculations with time_t, which
- * is not defined in the standard but works on POSIX-conformant
- * systems. If anyone uses something different, then this would need
- * improvement, or an alternative approach needs to be found.
+ * This is a portable replacement for the deprecated timegm(),
+ * copied from the man page.
*/
static time_t
-my_timegm(struct tm *t)
+my_timegm(struct tm *tm)
{
- time_t tl, tb;
- struct tm *tg;
-
- tl = mktime(t);
- if (tl == -1) {
- t->tm_hour--;
- tl = mktime(t);
- if (tl == -1)
- return -1; /* can't deal with output from strptime */
- tl += 3600;
- }
- tg = gmtime(&tl);
- tg->tm_isdst = 0;
- tb = mktime(tg);
- if (tb == -1) {
- tg->tm_hour--;
- tb = mktime(tg);
- if (tb == -1)
- return -1; /* can't deal with output from gmtime */
- tb += 3600;
- }
- return (tl - (tb - tl));
+ time_t ret;
+ char *tz;
+
+ tz = getenv("TZ");
+ setenv("TZ", "", 1);
+ tzset();
+ ret = mktime(tm);
+ if (tz)
+ setenv("TZ", tz, 1);
+ else
+ unsetenv("TZ");
+ tzset();
+ return ret;
}
@@ -124,6 +107,7 @@ parse_xml_timestring(gchar *ts, gchar *format) {
/* strptime needs an initialized struct, or unpredictable
* behaviour might occur */
memset(&tm, 0, sizeof(struct tm));
+ tm.tm_isdst = -1;
if (G_UNLIKELY(strptime(ts, format, &tm) == NULL))
return t;
More information about the Xfce4-commits
mailing list