[tz] setting TZ and calling localtime_r

Paul Eggert eggert at cs.ucla.edu
Fri Dec 15 17:45:24 UTC 2017


On 12/15/2017 01:25 AM, Guy Harris wrote:
> as I read the Single UNIX Specification, localtime_r() (not surprisingly) honors TZ, but does not necessarily honor*changes*  in TZ unless you call tzset() before calling localtime_r().

Yes, that's my understanding too (and I agree POSIX is vague here). That 
is, as I understand it, although localtime_r and tzset are both required 
to lock each other out safely, localtime_r is not required to call tzset 
(though it is allowed to).

Also, behavior is undefined if one thread calls tzset (perhaps via 
localtime, ugh) while another thread is modifying TZ or any other 
environment variable (either directly, or via putenv/setenv).

Portable multithreaded programs need to call tzset before they start 
threads that care about time, and they should run all their threads in 
the same time zone. This limitation is fixed by localtime_rz etc., which 
is in the reference implementation and in NetBSD but not elsewhere (yet).




More information about the tz mailing list