Mail Archives: cygwin/2010/10/29/17:55:11
--------------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 <time.h>
> #include <stdio.h>
>=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--
- Raw text -