On 10/30/2010 8:58 AM, Ken Brown wrote:
I've looked at Cygwin's localtime.cc, and the behavior I'm complaining
about is caused by the following code at the beginning of tzset:

        const char *    name = getenv("TZ");

        if (name == NULL) {
                if (!lcl_is_set)
                        tzsetwall();
                goto out;
        }

So getting rid of 'if (!lcl_is_set)' would solve the problem.  But this
would be inefficient, because it would mean that tzsetwall gets called
every time tzset is called if TZ is never set.  To get around that, one
could have tzsetwall set TZ.

It seems that tzset and tzsetwall used to behave the way I'm proposing
before the following two changes were made:

2007-12-11  Corinna Vinschen<cori...@vinschen.de>

        * localtime.cc (tzset): Call tzsetwall only if it hasn't been
        called before.

2007-08-01  Corinna Vinschen<cori...@vinschen.de>

        * localtime.cc (tzsetwall): Don't set TZ.

I've just found the reason for the 2007-08-01 change:

    http://www.cygwin.com/ml/cygwin/2007-08/msg00041.html

So I don't know what should be done.

How's the attached patch? I'm not set up to build cygwin1.dll, so I can't test it right now. I hope the intent is clear in case I got something wrong.

Ken
--- localtime.cc.orig   2009-06-14 05:35:35.000000000 -0400
+++ localtime.cc        2010-10-30 13:28:36.421875000 -0400
@@ -597,6 +597,7 @@
 static char            lcl_TZname[TZ_STRLEN_MAX + 1];
 static int             lcl_is_set;
 static int             gmt_is_set;
+static int             TZ_is_set;
 
 #define tzname _tzname
 #undef _tzname
@@ -1479,11 +1480,14 @@
        const char *    name = getenv("TZ");
 
        if (name == NULL) {
-               if (!lcl_is_set)
+               if (!lcl_is_set || TZ_is_set) {
+                       TZ_is_set = 0;
                        tzsetwall();
+               }
                goto out;
        }
 
+       TZ_is_set = 1;
        if (lcl_is_set > 0  &&  strcmp(lcl_TZname, name) == 0)
                goto out;
        lcl_is_set = (strlen(name) < sizeof (lcl_TZname));

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply via email to