X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Message-ID: <4CCB42AF.2090907@redhat.com> Date: Fri, 29 Oct 2010 15:54:55 -0600 From: Eric Blake User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc13 Mnenhy/0.8.3 Thunderbird/3.1.4 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: localtime and TZ References: <4CCB4025 DOT 6070405 AT cornell DOT edu> In-Reply-To: <4CCB4025.6070405@cornell.edu> OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigD30FE42074E866AA8EF41C47" X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --------------enigD30FE42074E866AA8EF41C47 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 10/29/2010 03:44 PM, Ken Brown wrote: > While trying to debug a timezone problem in the Cygwin build of emacs, I'= ve come across a difference between Cygwin and Linux in the behavior of loc= altime with respect to TZ. Suppose I set TZ, call localtime, unset TZ, and= call localtime again. On Cygwin, the second call to localtime re-uses the= previous value of TZ. On Linux, localtime reverts to giving local informa= tion, just as if TZ had never been set. Here's a Simple Test Case: >=20 > #include > #include >=20 > extern char **environ; >=20 > void > unset_TZ (void) > { > char **from, **to; > for (to =3D from =3D environ; (*to =3D *from); from++) > if (! (to[0][0] =3D=3D 'T' && to[0][1] =3D=3D 'Z' && to[0][2] =3D=3D = '=3D')) > to++; > } Messing directly with environ is your problem. POSIX says that it is only portable to traverse (but not modify) environ's contents, or to completely assign a new array to environ. By going behind cygwin's back, and not using unsetenv(), you have violated POSIX and can't expect sane results. >=20 > int > main (void) > { > time_t now =3D time ((time_t *) 0); > printf ("TZ is initially unset; hour =3D %d\n", localtime (&now)->tm_ho= ur); > putenv ("TZ=3DGMT0"); > printf ("TZ=3DGMT0; hour =3D %d\n", localtime (&now)->tm_hour); > unset_TZ (); > printf ("TZ unset; hour =3D %d\n", localtime (&now)->tm_hour); > putenv ("TZ=3DPST8"); > printf ("TZ=3DPST8; hour =3D %d\n", localtime (&now)->tm_hour); > unset_TZ (); > printf ("TZ unset again; hour =3D %d\n", localtime (&now)->tm_hour); > } If properly using unsetenv("TZ") still causes problems, then we should investigate further. --=20 Eric Blake eblake AT redhat DOT com +1-801-349-2682 Libvirt virtualization library http://libvirt.org --------------enigD30FE42074E866AA8EF41C47 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJMy0KvAAoJEKeha0olJ0NqwN0IAJOnPp6t6ZgxxzizseAenUek Xne+3qo4gisExWagdC0T5nCFRqpgsFt24Hfo1NXGvdoFDX8GU/0BRxUf4b5wDGOR DlXw26o0/F5gxmxLUZ2IhMhcGDEh0A3TsaVM2qhgwXRc/rL7skFO2RLbi6zMWeku fWrLtYWuVXFJNKo9mZo+H+G4l7SjD7j8Ddh2BhkJdEkfm4PPw1ptpeBJdMoS8rLQ ow6elineF4ZZc8LMqxGEwAEXzPNZzJ4/IcH2KD+H6x1McuGsbLayMJcr9buv0i/E uA1zsATeP6rqLLzD6RMZgi9EMFhUVVUSLemBFiy+nQxuPrQJziVmMW8JtpBGdoI= =7t7s -----END PGP SIGNATURE----- --------------enigD30FE42074E866AA8EF41C47--