This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge pull request #71 from richardleach/patch-1
[metaconfig.git] / U / threads / d_localtime_r.U
index dba7b16..53fa397 100644 (file)
@@ -9,7 +9,7 @@
 ?RCS:
 ?MAKE:d_localtime_r d_localtime_r_needs_tzset localtime_r_proto: Inlibc \
        cat run Protochk Hasproto i_systypes usethreads i_time i_systime \
-       rm_try Compile
+       rm_try Compile extern_C i_stdlib i_unistd i_malloc
 ?MAKE: -pick add $@ %<
 ?S:d_localtime_r:
 ?S:    This variable conditionally defines the HAS_LOCALTIME_R symbol,
@@ -33,7 +33,7 @@
 ?C:LOCALTIME_R_NEEDS_TZSET:
 ?C:    Many libc's localtime_r implementations do not call tzset,
 ?C:    making them differ from localtime(), and making timezone
-?C:    changes using $ENV{TZ} without explicitly calling tzset
+?C:    changes using \$ENV{TZ} without explicitly calling tzset
 ?C:    impossible. This symbol makes us call tzset before localtime_r
 ?C:.
 ?H:?%<:#$d_localtime_r_needs_tzset LOCALTIME_R_NEEDS_TZSET /**/
 ?C:    REENTRANT_PROTO_T_ABC macros of reentr.h if d_localtime_r
 ?C:    is defined.
 ?C:.
-?H:#$d_localtime_r HAS_LOCALTIME_R        /**/
-?H:#define LOCALTIME_R_PROTO $localtime_r_proto           /**/
+?H:#$d_localtime_r HAS_LOCALTIME_R     /**/
+?H:#define LOCALTIME_R_PROTO $localtime_r_proto        /**/
 ?H:.
 ?T:try hdrs d_localtime_r_proto
-?LINT:set d_localtime_r
-?LINT:set d_localtime_r_needs_tzset
-?LINT:set localtime_r_proto
+?F:!try
 : see if localtime_r exists
 set localtime_r d_localtime_r
 eval $inlibc
@@ -75,15 +73,15 @@ case "$d_localtime_r" in
        define)
        case "$localtime_r_proto" in
        ''|0) try='struct tm* localtime_r(const time_t*, struct tm*);'
-       ./protochk "extern $try" $hdrs && localtime_r_proto=S_TS ;;
+       ./protochk "$extern_C $try" $hdrs && localtime_r_proto=S_TS ;;
        esac
        case "$localtime_r_proto" in
        ''|0) try='int localtime_r(const time_t*, struct tm*);'
-       ./protochk "extern $try" $hdrs && localtime_r_proto=I_TS ;;
+       ./protochk "$extern_C $try" $hdrs && localtime_r_proto=I_TS ;;
        esac
        case "$localtime_r_proto" in
        ''|0)   d_localtime_r=undef
-               localtime_r_proto=0
+               localtime_r_proto=0
                echo "Disabling localtime_r, cannot determine prototype." >&4 ;;
        * )     case "$localtime_r_proto" in
                REENTRANT_PROTO*) ;;
@@ -111,13 +109,30 @@ REENTRANT_PROTO*)
 /*  Does our libc's localtime_r call tzset ?
  *  return 0 if so, 1 otherwise.
  */
-#include <sys/types.h>
-#include <unistd.h>
-#include <time.h>
+#$i_systypes   I_SYS_TYPES
+#$i_unistd     I_UNISTD
+#$i_time       I_TIME
+#$i_stdlib     I_STDLIB
+#$i_malloc     I_MALLOC
+#ifdef I_SYS_TYPES
+#  include <sys/types.h>
+#endif
+#ifdef I_UNISTD
+#  include <unistd.h>
+#endif
+#ifdef I_TIME
+#  include <time.h>
+#endif
+#ifdef I_STDLIB
+#include <stdlib.h>
+#endif
 #include <string.h>
-#include <malloc.h>
+#ifdef I_MALLOC
+#  include <malloc.h>
+#endif
 int main()
 {
+    int result = 0;
     time_t t = time(0L);
     char w_tz[]="TZ" "=GMT+5",
         e_tz[]="TZ" "=GMT-5",
@@ -136,8 +151,10 @@ int main()
     localtime_r(&t, &tm_w);
 
     if( memcmp(&tm_e, &tm_w, sizeof(struct tm)) == 0 )
-       return 1;
-    return 0;
+       result = 1;
+
+    free(tz_e);free(tz_w);
+    return result;
 }
 EOCP
        set try