Blob Blame Raw
--- perl-5.8.8/config_h.SH.bz172396	2005-10-31 13:13:05.000000000 -0500
+++ perl-5.8.8/config_h.SH	2006-05-11 16:20:36.000000000 -0400
@@ -1912,7 +1912,18 @@
  */
 #$d_localtime_r HAS_LOCALTIME_R	   /**/
 #define LOCALTIME_R_PROTO $localtime_r_proto	   /**/
-
+/* LOCALTIME_R_NEEDS_TZSET :
+ *  many libc's localtime_r implementations do not call tzset,
+ *  making them differ from localtime(), and making timezone
+ *  changes using $ENV{TZ} without explicitly calling tzset
+ *  impossible. This symbol makes us call tzset before localtime_r:
+ */
+#$d_localtime_r_needs_tzset LOCALTIME_R_NEEDS_TZSET /**/
+#ifdef LOCALTIME_R_NEEDS_TZSET
+#define L_R_TZSET tzset(),
+#else
+#define L_R_TZSET
+#endif 
 /* HAS_LONG_DOUBLE:
  *	This symbol will be defined if the C compiler supports long
  *	doubles.
--- perl-5.8.8/reentr.inc.bz172396	2006-05-11 16:20:36.000000000 -0400
+++ perl-5.8.8/reentr.inc	2006-05-11 16:20:36.000000000 -0400
@@ -1368,10 +1368,10 @@
 #ifdef HAS_LOCALTIME_R
 #   undef localtime
 #   if !defined(localtime) && LOCALTIME_R_PROTO == REENTRANT_PROTO_S_TS
-#       define localtime(a) (localtime_r(a, &PL_reentrant_buffer->_localtime_struct) ? &PL_reentrant_buffer->_localtime_struct : 0)
+#       define localtime(a) ( L_R_TZSET localtime_r(a, &PL_reentrant_buffer->_localtime_struct) ? &PL_reentrant_buffer->_localtime_struct : 0)
 #   endif
 #   if !defined(localtime) && LOCALTIME_R_PROTO == REENTRANT_PROTO_I_TS
-#       define localtime(a) (localtime_r(a, &PL_reentrant_buffer->_localtime_struct) == 0 ? &PL_reentrant_buffer->_localtime_struct : 0)
+#       define localtime(a) ( L_R_TZSET localtime_r(a, &PL_reentrant_buffer->_localtime_struct) == 0 ? &PL_reentrant_buffer->_localtime_struct : 0)
 #   endif
 #endif /* HAS_LOCALTIME_R */
 
--- perl-5.8.8/Configure.bz172396	2006-05-11 16:20:36.000000000 -0400
+++ perl-5.8.8/Configure	2006-05-11 16:21:47.000000000 -0400
@@ -542,6 +542,7 @@
 d_libm_lib_version=''
 d_link=''
 d_localtime_r=''
+d_localtime_r_needs_tzset=''
 localtime_r_proto=''
 d_locconv=''
 d_lockf=''
@@ -14261,7 +14262,59 @@
 *)	localtime_r_proto=0
 	;;
 esac
+: see if localtime_r calls tzset
+case "$localtime_r_proto" in
+REENTRANT_PROTO*) 
+	$cat >try.c <<EOCP
+/*  Does our libc's localtime_r call tzset ?
+ *  return 0 if so, 1 otherwise.
+ */ 
+#include <sys/types.h>
+#include <unistd.h>
+#include <time.h>
+#include <string.h>
+#include <malloc.h>
+int main()
+{
+    time_t t = time(0L);
+    char w_tz[]="TZ=GMT+5",
+	 e_tz[]="TZ=GMT-5",
+	*tz_e = (char*)malloc(16),
+	*tz_w = (char*)malloc(16);
+    struct tm tm_e, tm_w;
+    memset(&tm_e,'\0',sizeof(struct tm));
+    memset(&tm_w,'\0',sizeof(struct tm));
+    strcpy(tz_e,e_tz);
+    strcpy(tz_w,w_tz);
 
+    putenv(tz_e);
+    localtime_r(&t, &tm_e);    
+    
+    putenv(tz_w);
+    localtime_r(&t, &tm_w);    
+
+    if( memcmp(&tm_e, &tm_w, sizeof(struct tm)) == 0 )
+	return 1;
+    return 0;
+}
+EOCP
+	set try
+	if eval $compile; then	
+	    if ./try; then
+		d_localtime_r_needs_tzset=undef;
+	    else
+		d_localtime_r_needs_tzset=define;
+	    fi;
+	    rm -f ./try;
+	else
+	    d_localtime_r_needs_tzset=undef;
+	fi;
+	rm -f try.c;
+     ;;
+  *)
+     d_localtime_r_needs_tzset=undef;
+     ;;
+esac
 : see if localeconv exists
 set localeconv d_locconv
 eval $inlibc
@@ -21220,6 +21273,7 @@
 d_libm_lib_version='$d_libm_lib_version'
 d_link='$d_link'
 d_localtime_r='$d_localtime_r'
+d_localtime_r_needs_tzset='$d_localtime_r_needs_tzset'
 d_locconv='$d_locconv'
 d_lockf='$d_lockf'
 d_longdbl='$d_longdbl'