3 ?RCS: Copyright (c) 2008 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 ?MAKE:sGMTIME_max sGMTIME_min sLOCALTIME_max sLOCALTIME_min: cat rm_try \
9 Setvar Compile run i_values
10 ?MAKE: -pick add $@ %<
12 ?S: This variable defines the maximum value of the time_t offset that
13 ?S: the system function gmtime () accepts
16 ?S: This variable defines the minimum value of the time_t offset that
17 ?S: the system function gmtime () accepts
20 ?S: This variable defines the maximum value of the time_t offset that
21 ?S: the system function localtime () accepts
24 ?S: This variable defines the minimum value of the time_t offset that
25 ?S: the system function localtime () accepts
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
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
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
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
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 /**/
54 : Check the max offset that gmtime and localtime accept
55 echo "Checking max offsets that gmtime () accepts"
58 define) yyy="#include <values.h>" ;;
62 case "$sGMTIME_min/$sGMTIME_max" in
65 #include <sys/types.h>
74 void gm_check (time_t t, int min_year, int max_year)
78 /* Check tm_year overflow */
79 tmp->tm_year < min_year || tmp->tm_year > max_year)
90 gm_check (MAXLONG, 69, 0x7fffffff);
92 if (tmp == NULL || tmp->tm_year < 0) {
93 for (i = 63; i >= 0; i--) {
94 time_t x = pt | ((time_t)1 << i);
95 if (x < 0 || x < pt) continue;
96 gm_check (x, 69, 0x7fffffff);
99 printf ("sGMTIME_max=%ld\n", pt);
108 gm_check (MINLONG, -1900, 70);
111 for (i = 36; i >= 0; i--) {
112 time_t x = pt - ((time_t)1 << i);
114 gm_check (x, -1900, 70);
117 printf ("sGMTIME_min=%ld\n", pt);
121 int main (int argc, char *argv[])
123 /* fprintf (stderr, "Sizeof time_t = %ld\n", sizeof (time_t)); */
130 if eval $compile; then
131 eval `$run ./try 2>/dev/null`
133 echo "Cannot determine sGMTIME_max and sGMTIME_min." >&4
139 echo "Checking max offsets that localtime () accepts"
141 case "$sLOCALTIME_min/$sLOCALTIME_max" in
144 #include <sys/types.h>
153 void local_check (time_t t, int min_year, int max_year)
155 if (sizeof (time_t) > 4 && t > 0x7ffffffffffff000LL)
158 tmp = localtime (&t);
160 /* Check tm_year overflow */
161 tmp->tm_year < min_year || tmp->tm_year > max_year)
172 local_check (MAXLONG, 69, 0x7fffffff);
174 if (tmp == NULL || tmp->tm_year < 0) {
175 for (i = 63; i >= 0; i--) {
176 time_t x = pt | ((time_t)1 << i);
177 if (x < 0 || x < pt) continue;
178 local_check (x, 69, 0x7fffffff);
181 printf ("sLOCALTIME_max=%ld\n", pt);
190 local_check (MINLONG, -1900, 70);
193 for (i = 36; i >= 0; i--) {
194 time_t x = pt - ((time_t)1 << i);
196 local_check (x, -1900, 70);
199 printf ("sLOCALTIME_min=%ld\n", pt);
203 int main (int argc, char *argv[])
211 if eval $compile; then
212 eval `$run ./try 2>/dev/null`
214 echo "Cannot determine sLOCALTIME_max and sLOCALTIME_min." >&4