This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
94be218e65fee5f5c82b76881e4a6f675f6339d2
[metaconfig.git] / U / threads / d_localtime_r.U
1 ?RCS: $Id: d_localtime_r.U,v 0RCS:
2 ?RCS: Copyright (c) 2002,2003 Jarkko Hietaniemi
3 ?RCS: Copyright (c) 2006,2007 H.Merijn Brand
4 ?RCS:
5 ?RCS: You may distribute under the terms of either the GNU General Public
6 ?RCS: License or the Artistic License, as specified in the README file.
7 ?RCS:
8 ?RCS: Generated by the reentr.pl from the Perl 5.8 distribution.
9 ?RCS:
10 ?MAKE:d_localtime_r d_localtime_r_needs_tzset localtime_r_proto: Inlibc \
11         cat run Protochk Hasproto i_systypes usethreads i_time i_systime \
12         rm_try Compile extern_C
13 ?MAKE:  -pick add $@ %<
14 ?S:d_localtime_r:
15 ?S:     This variable conditionally defines the HAS_LOCALTIME_R symbol,
16 ?S:     which indicates to the C program that the localtime_r()
17 ?S:     routine is available.
18 ?S:.
19 ?S:d_localtime_r_needs_tzset:
20 ?S:     This variable conditionally defines the LOCALTIME_R_NEEDS_TZSET
21 ?S:     symbol, which makes us call tzset before localtime_r()
22 ?S:.
23 ?S:localtime_r_proto:
24 ?S:     This variable encodes the prototype of localtime_r.
25 ?S:     It is zero if d_localtime_r is undef, and one of the
26 ?S:     REENTRANT_PROTO_T_ABC macros of reentr.h if d_localtime_r
27 ?S:     is defined.
28 ?S:.
29 ?C:HAS_LOCALTIME_R:
30 ?C:     This symbol, if defined, indicates that the localtime_r routine
31 ?C:     is available to localtime re-entrantly.
32 ?C:.
33 ?C:LOCALTIME_R_NEEDS_TZSET:
34 ?C:     Many libc's localtime_r implementations do not call tzset,
35 ?C:     making them differ from localtime(), and making timezone
36 ?C:     changes using \$ENV{TZ} without explicitly calling tzset
37 ?C:     impossible. This symbol makes us call tzset before localtime_r
38 ?C:.
39 ?H:?%<:#$d_localtime_r_needs_tzset LOCALTIME_R_NEEDS_TZSET /**/
40 ?H:?%<:#ifdef LOCALTIME_R_NEEDS_TZSET
41 ?H:?%<:#define L_R_TZSET tzset(),
42 ?H:?%<:#else
43 ?H:?%<:#define L_R_TZSET
44 ?H:?%<:#endif
45 ?H:.
46 ?C:L_R_TZSET:
47 ?C:     If localtime_r() needs tzset, it is defined in this define
48 ?C:.
49 ?C:LOCALTIME_R_PROTO:
50 ?C:     This symbol encodes the prototype of localtime_r.
51 ?C:     It is zero if d_localtime_r is undef, and one of the
52 ?C:     REENTRANT_PROTO_T_ABC macros of reentr.h if d_localtime_r
53 ?C:     is defined.
54 ?C:.
55 ?H:#$d_localtime_r HAS_LOCALTIME_R         /**/
56 ?H:#define LOCALTIME_R_PROTO $localtime_r_proto    /**/
57 ?H:.
58 ?T:try hdrs d_localtime_r_proto
59 ?F:!try
60 : see if localtime_r exists
61 set localtime_r d_localtime_r
62 eval $inlibc
63 case "$d_localtime_r" in
64 "$define")
65         hdrs="$i_systypes sys/types.h define stdio.h $i_time time.h $i_systime sys/time.h"
66         case "$d_localtime_r_proto:$usethreads" in
67         ":define")      d_localtime_r_proto=define
68                 set d_localtime_r_proto localtime_r $hdrs
69                 eval $hasproto ;;
70         *)      ;;
71         esac
72         case "$d_localtime_r_proto" in
73         define)
74         case "$localtime_r_proto" in
75         ''|0) try='struct tm* localtime_r(const time_t*, struct tm*);'
76         ./protochk "$extern_C $try" $hdrs && localtime_r_proto=S_TS ;;
77         esac
78         case "$localtime_r_proto" in
79         ''|0) try='int localtime_r(const time_t*, struct tm*);'
80         ./protochk "$extern_C $try" $hdrs && localtime_r_proto=I_TS ;;
81         esac
82         case "$localtime_r_proto" in
83         ''|0)   d_localtime_r=undef
84                 localtime_r_proto=0
85                 echo "Disabling localtime_r, cannot determine prototype." >&4 ;;
86         * )     case "$localtime_r_proto" in
87                 REENTRANT_PROTO*) ;;
88                 *) localtime_r_proto="REENTRANT_PROTO_$localtime_r_proto" ;;
89                 esac
90                 echo "Prototype: $try" ;;
91         esac
92         ;;
93         *)      case "$usethreads" in
94                 define) echo "localtime_r has no prototype, not using it." >&4 ;;
95                 esac
96                 d_localtime_r=undef
97                 localtime_r_proto=0
98                 ;;
99         esac
100         ;;
101 *)      localtime_r_proto=0
102         ;;
103 esac
104
105 : see if localtime_r calls tzset
106 case "$localtime_r_proto" in
107 REENTRANT_PROTO*)
108         $cat >try.c <<EOCP
109 /*  Does our libc's localtime_r call tzset ?
110  *  return 0 if so, 1 otherwise.
111  */
112 #include <sys/types.h>
113 #include <unistd.h>
114 #include <time.h>
115 #include <string.h>
116 #include <malloc.h>
117 int main()
118 {
119     time_t t = time(0L);
120     char w_tz[]="TZ" "=GMT+5",
121          e_tz[]="TZ" "=GMT-5",
122         *tz_e = (char*)malloc(16),
123         *tz_w = (char*)malloc(16);
124     struct tm tm_e, tm_w;
125     memset(&tm_e,'\0',sizeof(struct tm));
126     memset(&tm_w,'\0',sizeof(struct tm));
127     strcpy(tz_e,e_tz);
128     strcpy(tz_w,w_tz);
129
130     putenv(tz_e);
131     localtime_r(&t, &tm_e);
132
133     putenv(tz_w);
134     localtime_r(&t, &tm_w);
135
136     if( memcmp(&tm_e, &tm_w, sizeof(struct tm)) == 0 )
137         return 1;
138     return 0;
139 }
140 EOCP
141         set try
142         if eval $compile; then
143             if $run ./try; then
144                 d_localtime_r_needs_tzset=undef;
145             else
146                 d_localtime_r_needs_tzset=define;
147             fi;
148         else
149             d_localtime_r_needs_tzset=undef;
150         fi;
151      ;;
152   *)
153      d_localtime_r_needs_tzset=undef;
154      ;;
155 esac
156 $rm_try
157