localtime() vs localtime_r()
davidxu at FreeBSD.org
Sun Mar 30 20:35:18 PDT 2008
According POSIX specification, it seems localtime_r() is not only
a reentrant version of localtime(), but also a performance-wise version.
[TSF] [Option Start] The localtime_r() function shall convert the time
in seconds since the Epoch pointed to by timer into a broken-down time
stored in the structure to which result points. The localtime_r()
function shall also return a pointer to that same structure.
Unlike localtime(), the reentrant version is not required to set tzname.
[TSF] [Option Start] If the reentrant version does not set tzname, it
shall not set daylight and shall not set timezone. [Option End]
Our implementation does set tzname, tomezone and daylight, it is a bit
slower than glibc because ours has to call getenv() everytime.
More information about the freebsd-current