Why does localtime() call tzset() but localtime_r() not?
Russ Allbery
rra at stanford.edu
Fri Jan 11 06:00:10 UTC 2008
"Jonathan Leffler" <jonathan.leffler at gmail.com> writes:
> Actually, the subject pretty much says it all.
> In tzcode2007k (also in 2007h), the code in localtime.c is:
>
> struct tm *
> localtime(const time_t *const timep)
> {
> tzset();
> return localsub(timep, 0L, &tm);
> }
>
> struct tm *
> localtime_r(const time_t *const timep, struct tm *tmp)
> {
> return localsub(timep, 0L, tmp);
> }
>
> I can't immediately see a justification for the asymmetry in the POSIX
> specification of these functions, but I could be missing something.
My guess is it's because tzset() sets global variables and hence isn't
threadsafe.
--
Russ Allbery (rra at stanford.edu) <http://www.eyrie.org/~eagle/>
More information about the tz
mailing list