This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
A builtin hard upper bound for sLOCALTIME_max to prevent AIX from stalling in the...
[metaconfig.git] / U / perl / time_size.U
CommitLineData
1879bbb7
MB
1?RCS: $Id$
2?RCS:
3?RCS: Copyright (c) 2008 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:
e2dd4a61
MB
8?MAKE:sGMTIME_max sGMTIME_min sLOCALTIME_max sLOCALTIME_min: cat rm_try \
9 Setvar Compile run i_values
1879bbb7
MB
10?MAKE: -pick add $@ %<
11?S:sGMTIME_max:
12?S: This variable defines the maximum value of the time_t offset that
13?S: the system function gmtime () accepts
14?S:.
15?S:sGMTIME_min:
16?S: This variable defines the minimum value of the time_t offset that
17?S: the system function gmtime () accepts
18?S:.
e2dd4a61
MB
19?S:sLOCALTIME_max:
20?S: This variable defines the maximum value of the time_t offset that
21?S: the system function localtime () accepts
22?S:.
23?S:sLOCALTIME_min:
24?S: This variable defines the minimum value of the time_t offset that
25?S: the system function localtime () accepts
26?S:.
1879bbb7
MB
27?C:GMTIME_MAX:
28?C: This symbol contains the maximum value for the time_t offset that
29?C: the system function gmtime () accepts, and defaults to 0
30?C:.
31?C:GMTIME_MIN:
32?C: This symbol contains the minimum value for the time_t offset that
33?C: the system function gmtime () accepts, and defaults to 0
34?C:.
e2dd4a61
MB
35?C:LOCALTIME_MAX:
36?C: This symbol contains the maximum value for the time_t offset that
37?C: the system function localtime () accepts, and defaults to 0
38?C:.
39?C:LOCALTIME_MIN:
40?C: This symbol contains the minimum value for the time_t offset that
41?C: the system function localtime () accepts, and defaults to 0
42?C:.
43?H:#define GMTIME_MAX $sGMTIME_max /**/
44?H:#define GMTIME_MIN $sGMTIME_min /**/
45?H:#define LOCALTIME_MAX $sLOCALTIME_max /**/
46?H:#define LOCALTIME_MIN $sLOCALTIME_min /**/
1879bbb7
MB
47?H:.
48?D:sGMTIME_max=0
49?D:sGMTIME_min=0
e2dd4a61
MB
50?D:sLOCALTIME_max=0
51?D:sLOCALTIME_min=0
1879bbb7 52?F:!try
9b506102 53?T:yyy
e2dd4a61 54: Check the max offset that gmtime and localtime accept
9b506102 55echo "Checking max offsets that gmtime () accepts"
1879bbb7 56
9b506102
MB
57case $i_values in
58 define) yyy="#include <values.h>" ;;
59 *) yyy="" ;;
60 esac
61
683dcd9d
MB
62case "$sGMTIME_min/$sGMTIME_max" in
63 0/0|/)
64 $cat >try.c <<EOCP
1879bbb7
MB
65#include <sys/types.h>
66#include <stdio.h>
67#include <time.h>
9b506102
MB
68$yyy
69
70int i;
71struct tm *tmp;
72time_t pt;
1879bbb7 73
9b506102
MB
74void gm_check (time_t t)
75{
1879bbb7 76 tmp = gmtime (&t);
9b506102
MB
77 if (tmp == NULL || tmp->tm_year < -1900)
78 tmp = NULL;
79 else
80 pt = t;
81 } /* gm_check */
1879bbb7 82
9b506102
MB
83int check_max ()
84{
e2dd4a61
MB
85 tmp = NULL;
86 pt = 0;
9b506102 87#ifdef MAXLONG
e2dd4a61 88 gm_check (MAXLONG);
9b506102 89#endif
e2dd4a61
MB
90 if (tmp == NULL || tmp->tm_year < 0) {
91 for (i = 63; i >= 0; i--) {
92 time_t x = pt | ((time_t)1 << i);
93 if (x < 0) continue;
94 gm_check (x);
95 }
96 }
97 printf ("sGMTIME_max=%ld\n", pt);
98 return (0);
99 } /* check_max */
1879bbb7 100
9b506102
MB
101int check_min ()
102{
e2dd4a61
MB
103 tmp = NULL;
104 pt = 0;
9b506102 105#ifdef MINLONG
e2dd4a61 106 gm_check (MINLONG);
9b506102 107#endif
e2dd4a61
MB
108 if (tmp == NULL) {
109 for (i = 36; i >= 0; i--) {
110 time_t x = pt - ((time_t)1 << i);
111 if (x > 0) continue;
112 gm_check (x);
113 }
114 }
115 printf ("sGMTIME_min=%ld\n", pt);
116 return (0);
117 } /* check_min */
9b506102
MB
118
119int main (int argc, char *argv[])
120{
e2dd4a61
MB
121 fprintf (stderr, "Sizeof time_t = %ld\n", sizeof (time_t));
122 check_max ();
123 check_min ();
124 return (0);
125 } /* main */
1879bbb7 126EOCP
683dcd9d
MB
127 set try
128 if eval $compile; then
129 eval `$run ./try`
130 else
131 echo "Cannot determine sGMTIME_max and sGMTIME_min." >&4
132 fi
133 $rm_try
134 ;;
135 esac
1879bbb7 136
e2dd4a61
MB
137echo "Checking max offsets that localtime () accepts"
138
683dcd9d
MB
139case "$sLOCALTIME_min/$sLOCALTIME_max" in
140 0/0|/)
141 $cat >try.c <<EOCP
e2dd4a61
MB
142#include <sys/types.h>
143#include <stdio.h>
144#include <time.h>
145$yyy
146
147int i;
148struct tm *tmp;
149time_t pt;
150
151void local_check (time_t t)
152{
20289907
MB
153 if (sizeof (time_t) > 4 && t > 0x7ffffffffffff000LL)
154 tmp = NULL;
155 else
156 tmp = localtime (&t);
e2dd4a61
MB
157 if (tmp == NULL || tmp->tm_year < -1900)
158 tmp = NULL;
159 else
160 pt = t;
161 } /* local_check */
162
163int check_max ()
164{
165 tmp = NULL;
166 pt = 0;
167#ifdef MAXLONG
168 local_check (MAXLONG);
169#endif
170 if (tmp == NULL || tmp->tm_year < 0) {
171 for (i = 63; i >= 0; i--) {
172 time_t x = pt | ((time_t)1 << i);
173 if (x < 0) continue;
174 local_check (x);
175 }
176 }
177 printf ("sLOCALTIME_max=%ld\n", pt);
178 return (0);
179 } /* check_max */
180
181int check_min ()
182{
183 tmp = NULL;
184 pt = 0;
185#ifdef MINLONG
186 local_check (MINLONG);
187#endif
188 if (tmp == NULL) {
189 for (i = 36; i >= 0; i--) {
190 time_t x = pt - ((time_t)1 << i);
191 if (x > 0) continue;
192 local_check (x);
193 }
194 }
195 printf ("sLOCALTIME_min=%ld\n", pt);
196 return (0);
197 } /* check_min */
198
199int main (int argc, char *argv[])
200{
201 check_max ();
202 check_min ();
203 return (0);
204 } /* main */
205EOCP
683dcd9d
MB
206 set try
207 if eval $compile; then
208 eval `$run ./try`
209 else
210 echo "Cannot determine sLOCALTIME_max and sLOCALTIME_min." >&4
211 fi
212 $rm_try
213 ;;
214 esac
e2dd4a61 215