delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/10/30/08:43:30

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.7 required=5.0 tests=AWL,BAYES_00,SPF_NEUTRAL,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Message-ID: <4CCC12E7.5060807@cornell.edu>
Date: Sat, 30 Oct 2010 08:43:19 -0400
From: Ken Brown <kbrown AT cornell DOT edu>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101013 Thunderbird/3.1.5
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: localtime and TZ
References: <4CCB4025 DOT 6070405 AT cornell DOT edu> <4CCB42AF DOT 2090907 AT redhat DOT com> <4CCB439B DOT 7060602 AT redhat DOT com> <4CCB4676 DOT 8080609 AT cornell DOT edu> <4CCB47A6 DOT 9010600 AT redhat DOT com> <4CCB561D DOT 5070304 AT cornell DOT edu>
In-Reply-To: <4CCB561D.5070304@cornell.edu>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 10/29/2010 7:17 PM, Ken Brown wrote:
> On 10/29/2010 6:16 PM, Eric Blake wrote:
>> On 10/29/2010 04:11 PM, Ken Brown wrote:
>>>
>>> Thanks, Eric.  I didn't know about any of this.  (I was using a modification of a configure test from the emacs sources.)
>>
>> Probably worth pointing it out to the emacs upstream, then :)
>>
>>>    But I get the same behavior with the following revised test case:
>>>
>>> #include<time.h>
>>> #include<stdio.h>
>>>
>>> int
>>> main (void)
>>> {
>>>     time_t now = time ((time_t *) 0);
>>>     printf ("TZ is initially unset; hour = %d\n", localtime (&now)->tm_hour);
>>>     putenv ("TZ=GMT0");
>>>     printf ("TZ=GMT0; hour = %d\n", localtime (&now)->tm_hour);
>>>     unsetenv("TZ");
>>>     printf ("TZ unset; hour = %d\n", localtime (&now)->tm_hour);
>>>     putenv ("TZ=PST8");
>>>     printf ("TZ=PST8; hour = %d\n", localtime (&now)->tm_hour);
>>>     unsetenv("TZ");
>>>     printf ("TZ unset again; hour = %d\n", localtime (&now)->tm_hour);
>>> }
>>>
>>> So the question remains whether this difference between Cygwin and Linux is a bug or by design.
>>
>> Apparently by design.  POSIX requires:
>>
>> http://www.opengroup.org/onlinepubs/9699919799/functions/localtime.html
>>
>> Local timezone information is used as though localtime() calls tzset().
>>
>> http://www.opengroup.org/onlinepubs/9699919799/functions/tzset.html
>>
>> The tzset() function shall use the value of the environment variable TZ
>> to set time conversion information used by ctime , localtime , mktime ,
>> and strftime . If TZ is absent from the environment,
>> implementation-defined default timezone information shall be used.
>
> Wouldn't you interpret this as meaning that the implementation-defined
> default timezone information should be the same every time localtime is
> called with TZ unset?  If not, what should a program do to get the
> "standard" default timezone information that it would get if TZ had
> never been set in the first place?

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  <corinna AT vinschen DOT de>

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

2007-08-01  Corinna Vinschen  <corinna AT vinschen DOT de>

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

Ken

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019