This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Be sure to use the correct type, so bits do not get wrapped
[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:
8?MAKE:sGMTIME_max sGMTIME_min: cat rm_try Setvar Compile run
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
32: Check the max offset that gmtime accepts
33echo "Checking max offset that gmtime () accepts"
34
35$cat >try.c <<'EOCP'
36#include <sys/types.h>
37#include <stdio.h>
38#include <time.h>
39int main () {
40 struct tm *tmp;
41 int i, y = 0;
42 time_t pt = 0;
43
44 for (i = 0; i < 78; i++) {
e408f0b3 45 time_t t = ((time_t)1 << i) - 1;
1879bbb7
MB
46 tmp = gmtime (&t);
47 if (tmp == NULL || tmp->tm_year < y) {
48 i--;
e408f0b3 49 printf ("%ld\n", pt);
1879bbb7
MB
50 return (i);
51 }
52
53 y = tmp->tm_year;
54 pt = t;
55 }
e408f0b3 56 printf ("%ld\n", pt);
1879bbb7
MB
57 return (0);
58 }
59EOCP
60set try
61if eval $compile; then
62 sGMTIME_max=`$run ./try`
63else
64 echo "Cannot determine sGMTIME_max"
65 fi
66$rm_try
67
68echo "Checking min offset that gmtime () accepts"
69
70$cat >try.c <<'EOCP'
71#include <sys/types.h>
72#include <stdio.h>
73#include <time.h>
74int main () {
75 struct tm *tmp;
76 int i, y = 70;
77 time_t pt = 0;
78
79 for (i = 0; i < 78; i++) {
e408f0b3 80 time_t t = - ((time_t)1 << i);
1879bbb7
MB
81 tmp = gmtime (&t);
82 if (tmp == NULL || tmp->tm_year > y) {
83 i--;
e408f0b3 84 printf ("%ld\n", pt);
1879bbb7
MB
85 return (i);
86 }
87
88 y = tmp->tm_year;
89 pt = t;
90 }
e408f0b3 91 printf ("%ld\n", pt);
1879bbb7
MB
92 return (0);
93 }
94EOCP
95set try
96if eval $compile; then
97 sGMTIME_min=`$run ./try`
98else
99 echo "Cannot determine sGMTIME_min"
100 fi
101$rm_try
102