This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fine-grained sGMTIME_min/max detection
[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:
9b506102 8?MAKE:sGMTIME_max sGMTIME_min: cat rm_try Setvar Compile run i_values
1879bbb7
MB
9?MAKE: -pick add $@ %<
10?S:sGMTIME_max:
11?S: This variable defines the maximum value of the time_t offset that
12?S: the system function gmtime () accepts
13?S:.
14?S:sGMTIME_min:
15?S: This variable defines the minimum value of the time_t offset that
16?S: the system function gmtime () accepts
17?S:.
18?C:GMTIME_MAX:
19?C: This symbol contains the maximum value for the time_t offset that
20?C: the system function gmtime () accepts, and defaults to 0
21?C:.
22?C:GMTIME_MIN:
23?C: This symbol contains the minimum value for the time_t offset that
24?C: the system function gmtime () accepts, and defaults to 0
25?C:.
26?H:#define GMTIME_MAX $sGMTIME_max /**/
27?H:#define GMTIME_MIN $sGMTIME_min /**/
28?H:.
29?D:sGMTIME_max=0
30?D:sGMTIME_min=0
31?F:!try
9b506102 32?T:yyy
1879bbb7 33: Check the max offset that gmtime accepts
9b506102 34echo "Checking max offsets that gmtime () accepts"
1879bbb7 35
9b506102
MB
36case $i_values in
37 define) yyy="#include <values.h>" ;;
38 *) yyy="" ;;
39 esac
40
41$cat >try.c <<EOCP
1879bbb7
MB
42#include <sys/types.h>
43#include <stdio.h>
44#include <time.h>
9b506102
MB
45$yyy
46
47int i;
48struct tm *tmp;
49time_t pt;
1879bbb7 50
9b506102
MB
51void gm_check (time_t t)
52{
1879bbb7 53 tmp = gmtime (&t);
9b506102
MB
54 if (tmp == NULL || tmp->tm_year < -1900)
55 tmp = NULL;
56 else
57 pt = t;
58 } /* gm_check */
1879bbb7 59
9b506102
MB
60int check_max ()
61{
62 tmp = NULL;
63 pt = 0;
64#ifdef MAXLONG
65 gm_check (MAXLONG);
66#endif
67 if (tmp == NULL || tmp->tm_year < 0) {
68 for (i = 63; i >= 0; i--) {
69 time_t x = pt | ((time_t)1 << i);
70 if (x < 0) continue;
71 gm_check (x);
72 }
1879bbb7 73 }
9b506102 74 printf ("sGMTIME_max=%ld\n", pt);
1879bbb7
MB
75 return (0);
76 }
1879bbb7 77
9b506102
MB
78int check_min ()
79{
80 tmp = NULL;
81 pt = 0;
82#ifdef MINLONG
83 gm_check (MINLONG);
84#endif
85 if (tmp == NULL) {
86 for (i = 36; i >= 0; i--) {
87 time_t x = pt - ((time_t)1 << i);
88 if (x > 0) continue;
89 gm_check (x);
1879bbb7 90 }
1879bbb7 91 }
9b506102 92 printf ("sGMTIME_min=%ld\n", pt);
1879bbb7
MB
93 return (0);
94 }
9b506102
MB
95
96int main (int argc, char *argv[])
97{
98 fprintf (stderr, "Sizeof time_t = %ld\n", sizeof (time_t));
99 check_max ();
100 check_min ();
101 return (0);
102 } /* main */
1879bbb7
MB
103EOCP
104set try
105if eval $compile; then
9b506102
MB
106 yyy=`$run ./try`
107 eval $yyy
1879bbb7 108else
9b506102 109 echo "Cannot determine sGMTIME_max and sGMTIME_min." >&4
1879bbb7
MB
110 fi
111$rm_try
112