From: H.Merijn Brand Date: Tue, 8 Jul 2008 20:00:24 +0000 (+0000) Subject: Fine-grained sGMTIME_min/max detection X-Git-Tag: 5.26.1~290 X-Git-Url: https://perl5.git.perl.org/metaconfig.git/commitdiff_plain/9b50610285ca710e1c177b9aea43da09b9d2a960?ds=sidebyside Fine-grained sGMTIME_min/max detection p4raw-id: //depot/metaconfig@34113 --- diff --git a/U/perl/time_size.U b/U/perl/time_size.U index 0b206b9..c2b9611 100644 --- a/U/perl/time_size.U +++ b/U/perl/time_size.U @@ -5,7 +5,7 @@ ?RCS: You may distribute under the terms of either the GNU General Public ?RCS: License or the Artistic License, as specified in the README file. ?RCS: -?MAKE:sGMTIME_max sGMTIME_min: cat rm_try Setvar Compile run +?MAKE:sGMTIME_max sGMTIME_min: cat rm_try Setvar Compile run i_values ?MAKE: -pick add $@ %< ?S:sGMTIME_max: ?S: This variable defines the maximum value of the time_t offset that @@ -29,74 +29,84 @@ ?D:sGMTIME_max=0 ?D:sGMTIME_min=0 ?F:!try +?T:yyy : Check the max offset that gmtime accepts -echo "Checking max offset that gmtime () accepts" +echo "Checking max offsets that gmtime () accepts" -$cat >try.c <<'EOCP' +case $i_values in + define) yyy="#include " ;; + *) yyy="" ;; + esac + +$cat >try.c < #include #include -int main () { - struct tm *tmp; - int i, y = 0; - time_t pt = 0; +$yyy + +int i; +struct tm *tmp; +time_t pt; - for (i = 0; i < 78; i++) { - time_t t = ((time_t)1 << i) - 1; +void gm_check (time_t t) +{ tmp = gmtime (&t); - if (tmp == NULL || tmp->tm_year < y) { - i--; - printf ("%ld\n", pt); - return (i); - } + if (tmp == NULL || tmp->tm_year < -1900) + tmp = NULL; + else + pt = t; + } /* gm_check */ - y = tmp->tm_year; - pt = t; +int check_max () +{ + tmp = NULL; + pt = 0; +#ifdef MAXLONG + gm_check (MAXLONG); +#endif + if (tmp == NULL || tmp->tm_year < 0) { + for (i = 63; i >= 0; i--) { + time_t x = pt | ((time_t)1 << i); + if (x < 0) continue; + gm_check (x); + } } - printf ("%ld\n", pt); + printf ("sGMTIME_max=%ld\n", pt); return (0); } -EOCP -set try -if eval $compile; then - sGMTIME_max=`$run ./try` -else - echo "Cannot determine sGMTIME_max" - fi -$rm_try -echo "Checking min offset that gmtime () accepts" - -$cat >try.c <<'EOCP' -#include -#include -#include -int main () { - struct tm *tmp; - int i, y = 70; - time_t pt = 0; - - for (i = 0; i < 78; i++) { - time_t t = - ((time_t)1 << i); - tmp = gmtime (&t); - if (tmp == NULL || tmp->tm_year > y) { - i--; - printf ("%ld\n", pt); - return (i); +int check_min () +{ + tmp = NULL; + pt = 0; +#ifdef MINLONG + gm_check (MINLONG); +#endif + if (tmp == NULL) { + for (i = 36; i >= 0; i--) { + time_t x = pt - ((time_t)1 << i); + if (x > 0) continue; + gm_check (x); } - - y = tmp->tm_year; - pt = t; } - printf ("%ld\n", pt); + printf ("sGMTIME_min=%ld\n", pt); return (0); } + +int main (int argc, char *argv[]) +{ + fprintf (stderr, "Sizeof time_t = %ld\n", sizeof (time_t)); + check_max (); + check_min (); + return (0); + } /* main */ EOCP set try if eval $compile; then - sGMTIME_min=`$run ./try` + yyy=`$run ./try` + eval $yyy else - echo "Cannot determine sGMTIME_min" + echo "Cannot determine sGMTIME_max and sGMTIME_min." >&4 fi $rm_try