Bug with localtime_r()?

Rich Neswold <>
Wed Jun 15 14:10:54 CEST 2005


I'm running R10B-5 on my NetBSD 2.0.2 system. I noticed that
erlang:localtime() was returning UTC time. It turns out that
'configure' detects localtime_r() on my system and uses it. However,
on NetBSD, the man page says:

     "localtime_r() does not imply initialization of the local time conversion
     information; the application may need to do so by calling tzset(3)."

Looking through the BEAM source, I couldn't find any reference to
tzset(3) so I added it to the emulator initialization. The man page
didn't seem to imply that each thread needed to call it, so I didn't
try to put tzset() in the process initialization code.

I rebuilt my OTP installation using the following patch, and now the
localtime functions work:

--- erts/emulator/sys/unix/sys.c.orig   2005-06-14 23:25:38.000000000 -0500
+++ erts/emulator/sys/unix/sys.c        2005-06-14 23:28:11.000000000 -0500
@@ -33,6 +33,10 @@
 #include <ctype.h>
 #include <sys/utsname.h>
+#include <time.h>
 #if !defined(USE_SELECT)
 #  ifdef HAVE_POLL_H
@@ -428,6 +432,9 @@
     if (isatty(0)) {
+    tzset();


AIM : rnezzy
ICQ : 174908475

More information about the erlang-patches mailing list