Why does localtime() call tzset() but localtime_r() not?

Paul Eggert eggert at CS.UCLA.EDU
Fri Jan 11 22:59:45 UTC 2008


"Jonathan Leffler" <jonathan.leffler at gmail.com> writes:

> I guess the POSIX manual allows this

POSIX is incoherent in this area.  It places hardly any requirements
on localtime_r; for example, localtime_r can be an alias for gmtime_r.

I think the intent is that localtime_r have read-only access to the
internal data that tzset initializes.  However, there's no clear POSIX
requirement on the application to call tzset before calling
localtime_r, nor there is any requirement on the implementation to
behave as if tzset were called before execution begins.

Since the standard is fuzzy in this area, portable code should invoke
tzset (or localtime or mktime or strftime) before invoking localtime_r.



More information about the tz mailing list