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
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.
8 ?RCS: Generated by the reentr.pl from the Perl 5.8 distribution.
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 $@ %<
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.
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()
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
30 ?C: This symbol, if defined, indicates that the localtime_r routine
31 ?C: is available to localtime re-entrantly.
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
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(),
43 ?H:?%<:#define L_R_TZSET
47 ?C: If localtime_r() needs tzset, it is defined in this define
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
55 ?H:#$d_localtime_r HAS_LOCALTIME_R /**/
56 ?H:#define LOCALTIME_R_PROTO $localtime_r_proto /**/
58 ?T:try hdrs d_localtime_r_proto
60 : see if localtime_r exists
61 set localtime_r d_localtime_r
63 case "$d_localtime_r" in
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
72 case "$d_localtime_r_proto" in
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 ;;
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 ;;
82 case "$localtime_r_proto" in
83 ''|0) d_localtime_r=undef
85 echo "Disabling localtime_r, cannot determine prototype." >&4 ;;
86 * ) case "$localtime_r_proto" in
88 *) localtime_r_proto="REENTRANT_PROTO_$localtime_r_proto" ;;
90 echo "Prototype: $try" ;;
93 *) case "$usethreads" in
94 define) echo "localtime_r has no prototype, not using it." >&4 ;;
101 *) localtime_r_proto=0
105 : see if localtime_r calls tzset
106 case "$localtime_r_proto" in
109 /* Does our libc's localtime_r call tzset ?
110 * return 0 if so, 1 otherwise.
112 #include <sys/types.h>
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));
131 localtime_r(&t, &tm_e);
134 localtime_r(&t, &tm_w);
136 if( memcmp(&tm_e, &tm_w, sizeof(struct tm)) == 0 )
142 if eval $compile; then
144 d_localtime_r_needs_tzset=undef;
146 d_localtime_r_needs_tzset=define;
149 d_localtime_r_needs_tzset=undef;
153 d_localtime_r_needs_tzset=undef;