Commit | Line | Data |
---|---|---|
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 | 55 | echo "Checking max offsets that gmtime () accepts" |
1879bbb7 | 56 | |
9b506102 MB |
57 | case $i_values in |
58 | define) yyy="#include <values.h>" ;; | |
59 | *) yyy="" ;; | |
60 | esac | |
61 | ||
683dcd9d MB |
62 | case "$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 | ||
70 | int i; | |
71 | struct tm *tmp; | |
72 | time_t pt; | |
1879bbb7 | 73 | |
9b506102 MB |
74 | void 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 |
83 | int 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 |
101 | int 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 | |
119 | int 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 | 126 | EOCP |
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 |
137 | echo "Checking max offsets that localtime () accepts" |
138 | ||
683dcd9d MB |
139 | case "$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 | ||
147 | int i; | |
148 | struct tm *tmp; | |
149 | time_t pt; | |
150 | ||
151 | void local_check (time_t t) | |
152 | { | |
153 | tmp = localtime (&t); | |
154 | if (tmp == NULL || tmp->tm_year < -1900) | |
155 | tmp = NULL; | |
156 | else | |
157 | pt = t; | |
158 | } /* local_check */ | |
159 | ||
160 | int check_max () | |
161 | { | |
162 | tmp = NULL; | |
163 | pt = 0; | |
164 | #ifdef MAXLONG | |
165 | local_check (MAXLONG); | |
166 | #endif | |
167 | if (tmp == NULL || tmp->tm_year < 0) { | |
168 | for (i = 63; i >= 0; i--) { | |
169 | time_t x = pt | ((time_t)1 << i); | |
170 | if (x < 0) continue; | |
171 | local_check (x); | |
172 | } | |
173 | } | |
174 | printf ("sLOCALTIME_max=%ld\n", pt); | |
175 | return (0); | |
176 | } /* check_max */ | |
177 | ||
178 | int check_min () | |
179 | { | |
180 | tmp = NULL; | |
181 | pt = 0; | |
182 | #ifdef MINLONG | |
183 | local_check (MINLONG); | |
184 | #endif | |
185 | if (tmp == NULL) { | |
186 | for (i = 36; i >= 0; i--) { | |
187 | time_t x = pt - ((time_t)1 << i); | |
188 | if (x > 0) continue; | |
189 | local_check (x); | |
190 | } | |
191 | } | |
192 | printf ("sLOCALTIME_min=%ld\n", pt); | |
193 | return (0); | |
194 | } /* check_min */ | |
195 | ||
196 | int main (int argc, char *argv[]) | |
197 | { | |
198 | check_max (); | |
199 | check_min (); | |
200 | return (0); | |
201 | } /* main */ | |
202 | EOCP | |
683dcd9d MB |
203 | set try |
204 | if eval $compile; then | |
205 | eval `$run ./try` | |
206 | else | |
207 | echo "Cannot determine sLOCALTIME_max and sLOCALTIME_min." >&4 | |
208 | fi | |
209 | $rm_try | |
210 | ;; | |
211 | esac | |
e2dd4a61 | 212 |