This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
threads/d_nl_langinfo_l.U: Rmv trailing space
[metaconfig.git] / U / threads / d_localtime_r.U
CommitLineData
0ed44c70 1?RCS: $Id: d_localtime_r.U,v 0RCS:
55e6b58d 2?RCS: Copyright (c) 2002,2003 Jarkko Hietaniemi
2cb64bf6 3?RCS: Copyright (c) 2006,2007 H.Merijn Brand
0ed44c70
JH
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:
914abcdc
JH
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 \
c3173023 12 rm_try Compile extern_C i_stdlib i_unistd i_string i_malloc
eed88ce0 13?MAKE: -pick add $@ %<
959f3c4c 14?S:d_localtime_r:
eed88ce0
JH
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.
959f3c4c 18?S:.
89b0533f
BH
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:.
8e87a72a 23?S:localtime_r_proto:
eed88ce0 24?S: This variable encodes the prototype of localtime_r.
05fdd8fd
JH
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.
8e87a72a 28?S:.
959f3c4c 29?C:HAS_LOCALTIME_R:
eed88ce0
JH
30?C: This symbol, if defined, indicates that the localtime_r routine
31?C: is available to localtime re-entrantly.
959f3c4c 32?C:.
89b0533f
BH
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
d6c407a4 36?C: changes using \$ENV{TZ} without explicitly calling tzset
89b0533f
BH
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:.
8e87a72a 49?C:LOCALTIME_R_PROTO:
eed88ce0 50?C: This symbol encodes the prototype of localtime_r.
05fdd8fd
JH
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.
8e87a72a 54?C:.
eed88ce0
JH
55?H:#$d_localtime_r HAS_LOCALTIME_R /**/
56?H:#define LOCALTIME_R_PROTO $localtime_r_proto /**/
959f3c4c 57?H:.
f42a43f5 58?T:try hdrs d_localtime_r_proto
0065f4af 59?F:!try
959f3c4c
JH
60: see if localtime_r exists
61set localtime_r d_localtime_r
62eval $inlibc
8e87a72a
JH
63case "$d_localtime_r" in
64"$define")
09c12c20 65 hdrs="$i_systypes sys/types.h define stdio.h $i_time time.h $i_systime sys/time.h"
9bb0d1dd
JH
66 case "$d_localtime_r_proto:$usethreads" in
67 ":define") d_localtime_r_proto=define
f42a43f5
JH
68 set d_localtime_r_proto localtime_r $hdrs
69 eval $hasproto ;;
70 *) ;;
71 esac
72 case "$d_localtime_r_proto" in
73 define)
46953654 74 case "$localtime_r_proto" in
5002a627 75 ''|0) try='struct tm* localtime_r(const time_t*, struct tm*);'
cce04e58 76 ./protochk "$extern_C $try" $hdrs && localtime_r_proto=S_TS ;;
46953654
JH
77 esac
78 case "$localtime_r_proto" in
5002a627 79 ''|0) try='int localtime_r(const time_t*, struct tm*);'
cce04e58 80 ./protochk "$extern_C $try" $hdrs && localtime_r_proto=I_TS ;;
46953654
JH
81 esac
82 case "$localtime_r_proto" in
81d83c43 83 ''|0) d_localtime_r=undef
5002a627 84 localtime_r_proto=0
f42a43f5 85 echo "Disabling localtime_r, cannot determine prototype." >&4 ;;
f2dee704
JH
86 * ) case "$localtime_r_proto" in
87 REENTRANT_PROTO*) ;;
88 *) localtime_r_proto="REENTRANT_PROTO_$localtime_r_proto" ;;
89 esac
90 echo "Prototype: $try" ;;
46953654 91 esac
8e87a72a 92 ;;
9bb0d1dd
JH
93 *) case "$usethreads" in
94 define) echo "localtime_r has no prototype, not using it." >&4 ;;
95 esac
81d83c43
JH
96 d_localtime_r=undef
97 localtime_r_proto=0
9bb0d1dd 98 ;;
f42a43f5
JH
99 esac
100 ;;
5002a627
JH
101*) localtime_r_proto=0
102 ;;
8e87a72a 103esac
959f3c4c 104
89b0533f
BH
105: see if localtime_r calls tzset
106case "$localtime_r_proto" in
107REENTRANT_PROTO*)
108 $cat >try.c <<EOCP
109/* Does our libc's localtime_r call tzset ?
110 * return 0 if so, 1 otherwise.
111 */
c3173023
MB
112#$i_systypes I_SYS_TYPES
113#$i_unistd I_UNISTD
114#$i_time I_TIME
115#$i_stdlib I_STDLIB
116#$i_string I_STRING
117#$i_malloc I_MALLOC
118#ifdef I_SYS_TYPES
119# include <sys/types.h>
120#endif
121#ifdef I_UNISTD
122# include <unistd.h>
123#endif
124#ifdef I_TIME
125# include <time.h>
126#endif
127#ifdef I_STDLIB
128#include <stdlib.h>
129#endif
130#ifdef I_STRING
131# include <string.h>
132#else
133# include <strings.h>
134#endif
135#ifdef I_MALLOC
136# include <malloc.h>
137#endif
89b0533f
BH
138int main()
139{
140 time_t t = time(0L);
141 char w_tz[]="TZ" "=GMT+5",
142 e_tz[]="TZ" "=GMT-5",
143 *tz_e = (char*)malloc(16),
144 *tz_w = (char*)malloc(16);
145 struct tm tm_e, tm_w;
146 memset(&tm_e,'\0',sizeof(struct tm));
147 memset(&tm_w,'\0',sizeof(struct tm));
148 strcpy(tz_e,e_tz);
149 strcpy(tz_w,w_tz);
150
151 putenv(tz_e);
152 localtime_r(&t, &tm_e);
153
154 putenv(tz_w);
155 localtime_r(&t, &tm_w);
156
157 if( memcmp(&tm_e, &tm_w, sizeof(struct tm)) == 0 )
158 return 1;
159 return 0;
160}
161EOCP
162 set try
163 if eval $compile; then
914abcdc 164 if $run ./try; then
89b0533f
BH
165 d_localtime_r_needs_tzset=undef;
166 else
167 d_localtime_r_needs_tzset=define;
168 fi;
169 else
170 d_localtime_r_needs_tzset=undef;
171 fi;
172 ;;
173 *)
174 d_localtime_r_needs_tzset=undef;
175 ;;
176esac
2cb64bf6 177$rm_try
89b0533f 178