time zone problems with util/timegm.c on mingw32

Fabian Keil freebsd-listen at fabiankeil.de
Sun Jun 10 19:00:22 CEST 2007


A while ago I needed a fallback timegm() version
for Privoxy and chose the one from gnupg 1.x's
util/timegm.c because it appeared to be working
on mingw32 and the license was compatible.

Apparently I didn't test it properly, because I
just noticed that it causes time zone problems
if getenv("TZ") is NULL. On my Windows test system
this (now) seems to be the case.

As a result the first timegm() call changes the time
zone settings (for me it causes a 2h offset for
localtime() called later on) while the next timegm()
call fixes the problem again. The timegm() call after
that restarts the cycle ...

This, and a minor memory leak, can be fixed
(on my mingw32 test system) with:

--- util/timegm.c       Wed Jul 27 19:02:56 2005
+++ util/timegm.c.patched       Sun Jun 10 18:52:30 2007
@@ -54,13 +54,14 @@
          strcpy(old_zone,"TZ=");
          strcat(old_zone,zone);
          putenv(old_zone);     
+         free(old_zone);
        }
     }
   else
 #ifdef HAVE_UNSETENV
     unsetenv("TZ");
 #else
-    putenv("TZ");
+    putenv("TZ=");
 #endif
 
   tzset();

This is just FYI, I didn't check if it matters
for gnupg or if mingw32 is even supported.

I'm interested to know though, if you are aware of any
platforms which have neither timegm() nor unsetenv(),
but support putenv("TZ") to unset TZ, but not putenv("TZ=")?

Fabian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : /pipermail/attachments/20070610/46441e21/attachment.pgp 


More information about the Gnupg-devel mailing list