apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject cvs commit: apr-util/test testdate.c
Date Thu, 31 May 2001 05:14:42 GMT
jerenkrantz    01/05/30 22:14:41

  Modified:    test     testdate.c
  Log:
  APRized version of testdate.  This is from my patch from a long
  time ago posted to new-httpd.  There seems to be some subtle bugs that
  need to be tracked down.  My guess is the bug might be within testdate.
  
  % ./testdate | grep "^No "
  No  2146998227000000 0 Wed, 13 Jan 2038 12:23:47 GMT
  No  2146487676000000 0 Thu, 07 Jan 2038 14:34:36 GMT
  No  2146651317000000 0 Sat, 09 Jan 2038 12:01:57 GMT
  
  Revision  Changes    Path
  1.2       +107 -101  apr-util/test/testdate.c
  
  Index: testdate.c
  ===================================================================
  RCS file: /home/cvs/apr-util/test/testdate.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testdate.c	2001/05/31 05:10:46	1.1
  +++ testdate.c	2001/05/31 05:14:39	1.2
  @@ -10,109 +10,112 @@
    * 
    * Roy Fielding, 1996
    */
  -#define AP_DECLARE(x) x
   
   #include <stdio.h>
   #include <stdlib.h>
  -#include "util_date.h"
  +#include <time.h>
  +#include "apr_date.h"
   
  -static const long year2secs[] = {
  -             0L,    /* 1970 */
  -      31536000L,    /* 1971 */
  -      63072000L,    /* 1972 */
  -      94694400L,    /* 1973 */
  -     126230400L,    /* 1974 */
  -     157766400L,    /* 1975 */
  -     189302400L,    /* 1976 */
  -     220924800L,    /* 1977 */
  -     252460800L,    /* 1978 */
  -     283996800L,    /* 1979 */
  -     315532800L,    /* 1980 */
  -     347155200L,    /* 1981 */
  -     378691200L,    /* 1982 */
  -     410227200L,    /* 1983 */
  -     441763200L,    /* 1984 */
  -     473385600L,    /* 1985 */
  -     504921600L,    /* 1986 */
  -     536457600L,    /* 1987 */
  -     567993600L,    /* 1988 */
  -     599616000L,    /* 1989 */
  -     631152000L,    /* 1990 */
  -     662688000L,    /* 1991 */
  -     694224000L,    /* 1992 */
  -     725846400L,    /* 1993 */
  -     757382400L,    /* 1994 */
  -     788918400L,    /* 1995 */
  -     820454400L,    /* 1996 */
  -     852076800L,    /* 1997 */
  -     883612800L,    /* 1998 */
  -     915148800L,    /* 1999 */
  -     946684800L,    /* 2000 */
  -     978307200L,    /* 2001 */
  -    1009843200L,    /* 2002 */
  -    1041379200L,    /* 2003 */
  -    1072915200L,    /* 2004 */
  -    1104537600L,    /* 2005 */
  -    1136073600L,    /* 2006 */
  -    1167609600L,    /* 2007 */
  -    1199145600L,    /* 2008 */
  -    1230768000L,    /* 2009 */
  -    1262304000L,    /* 2010 */
  -    1293840000L,    /* 2011 */
  -    1325376000L,    /* 2012 */
  -    1356998400L,    /* 2013 */
  -    1388534400L,    /* 2014 */
  -    1420070400L,    /* 2015 */
  -    1451606400L,    /* 2016 */
  -    1483228800L,    /* 2017 */
  -    1514764800L,    /* 2018 */
  -    1546300800L,    /* 2019 */
  -    1577836800L,    /* 2020 */
  -    1609459200L,    /* 2021 */
  -    1640995200L,    /* 2022 */
  -    1672531200L,    /* 2023 */
  -    1704067200L,    /* 2024 */
  -    1735689600L,    /* 2025 */
  -    1767225600L,    /* 2026 */
  -    1798761600L,    /* 2027 */
  -    1830297600L,    /* 2028 */
  -    1861920000L,    /* 2029 */
  -    1893456000L,    /* 2030 */
  -    1924992000L,    /* 2031 */
  -    1956528000L,    /* 2032 */
  -    1988150400L,    /* 2033 */
  -    2019686400L,    /* 2034 */
  -    2051222400L,    /* 2035 */
  -    2082758400L,    /* 2036 */
  -    2114380800L,    /* 2037 */
  -    2145916800L     /* 2038 */
  +static const apr_time_t year2secs[] = {
  +             0LL,    /* 1970 */
  +      31536000LL,    /* 1971 */
  +      63072000LL,    /* 1972 */
  +      94694400LL,    /* 1973 */
  +     126230400LL,    /* 1974 */
  +     157766400LL,    /* 1975 */
  +     189302400LL,    /* 1976 */
  +     220924800LL,    /* 1977 */
  +     252460800LL,    /* 1978 */
  +     283996800LL,    /* 1979 */
  +     315532800LL,    /* 1980 */
  +     347155200LL,    /* 1981 */
  +     378691200LL,    /* 1982 */
  +     410227200LL,    /* 1983 */
  +     441763200LL,    /* 1984 */
  +     473385600LL,    /* 1985 */
  +     504921600LL,    /* 1986 */
  +     536457600LL,    /* 1987 */
  +     567993600LL,    /* 1988 */
  +     599616000LL,    /* 1989 */
  +     631152000LL,    /* 1990 */
  +     662688000LL,    /* 1991 */
  +     694224000LL,    /* 1992 */
  +     725846400LL,    /* 1993 */
  +     757382400LL,    /* 1994 */
  +     788918400LL,    /* 1995 */
  +     820454400LL,    /* 1996 */
  +     852076800LL,    /* 1997 */
  +     883612800LL,    /* 1998 */
  +     915148800LL,    /* 1999 */
  +     946684800LL,    /* 2000 */
  +     978307200LL,    /* 2001 */
  +    1009843200LL,    /* 2002 */
  +    1041379200LL,    /* 2003 */
  +    1072915200LL,    /* 2004 */
  +    1104537600LL,    /* 2005 */
  +    1136073600LL,    /* 2006 */
  +    1167609600LL,    /* 2007 */
  +    1199145600LL,    /* 2008 */
  +    1230768000LL,    /* 2009 */
  +    1262304000LL,    /* 2010 */
  +    1293840000LL,    /* 2011 */
  +    1325376000LL,    /* 2012 */
  +    1356998400LL,    /* 2013 */
  +    1388534400LL,    /* 2014 */
  +    1420070400LL,    /* 2015 */
  +    1451606400LL,    /* 2016 */
  +    1483228800LL,    /* 2017 */
  +    1514764800LL,    /* 2018 */
  +    1546300800LL,    /* 2019 */
  +    1577836800LL,    /* 2020 */
  +    1609459200LL,    /* 2021 */
  +    1640995200LL,    /* 2022 */
  +    1672531200LL,    /* 2023 */
  +    1704067200LL,    /* 2024 */
  +    1735689600LL,    /* 2025 */
  +    1767225600LL,    /* 2026 */
  +    1798761600LL,    /* 2027 */
  +    1830297600LL,    /* 2028 */
  +    1861920000LL,    /* 2029 */
  +    1893456000LL,    /* 2030 */
  +    1924992000LL,    /* 2031 */
  +    1956528000LL,    /* 2032 */
  +    1988150400LL,    /* 2033 */
  +    2019686400LL,    /* 2034 */
  +    2051222400LL,    /* 2035 */
  +    2082758400LL,    /* 2036 */
  +    2114380800LL,    /* 2037 */
  +    2145916800LL     /* 2038 */
   };
   
   const char month_snames[12][4] = {
       "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
   };
   
  -void gm_timestr_822(char *ts, time_t sec)
  +void gm_timestr_822(char *ts, apr_time_t sec)
   {
       static const char *const days[7]=
  -       {"Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  +        {"Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
       struct tm *tms;
  - 
  -    tms = gmtime(&sec);
  +    long ls = (long)sec;
  +
  +    tms = gmtime(&ls);
    
       sprintf(ts, "%s, %.2d %s %d %.2d:%.2d:%.2d GMT", days[tms->tm_wday],
               tms->tm_mday, month_snames[tms->tm_mon], tms->tm_year + 1900,
               tms->tm_hour, tms->tm_min, tms->tm_sec);
   }
   
  -void gm_timestr_850(char *ts, time_t sec)
  +void gm_timestr_850(char *ts, apr_time_t sec)
   {
       static const char *const days[7]=
  - {"Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  +           {"Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
  +            "Saturday"};
       struct tm *tms;
       int year;
  +    long ls = (long)sec;
    
  -    tms = gmtime(&sec);
  +    tms = gmtime(&ls);
   
       year = tms->tm_year;
       if (year >= 100) year -= 100;
  @@ -122,13 +125,14 @@
               tms->tm_hour, tms->tm_min, tms->tm_sec);
   }
   
  -void gm_timestr_ccc(char *ts, time_t sec)
  +void gm_timestr_ccc(char *ts, apr_time_t sec)
   {
       static const char *const days[7]=
          {"Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
       struct tm *tms;
  +    long ls = (long)sec;
    
  -    tms = gmtime(&sec);
  +    tms = gmtime(&ls);
    
       sprintf(ts, "%s %s %2d %.2d:%.2d:%.2d %d", days[tms->tm_wday],
               month_snames[tms->tm_mon], tms->tm_mday, 
  @@ -138,25 +142,26 @@
   int main (void)
   {
       int year, i;
  -    time_t guess;
  -    time_t offset = 0;
  - /* time_t offset = 0; */
  - /* time_t offset = ((31 + 28) * 24 * 3600) - 1; */
  -    time_t secstodate, newsecs;
  +    apr_time_t guess;
  +    apr_time_t offset = 0;
  + /* apr_time_t offset = 0; */
  + /* apr_time_t offset = ((31 + 28) * 24 * 3600) - 1; */
  +    apr_time_t secstodate, newsecs;
       char datestr[50];
   
       for (year = 1970; year < 2038; ++year) {
  -        secstodate = (time_t)year2secs[year - 1970] + offset;
  +        secstodate = year2secs[year - 1970] + offset;
           gm_timestr_822(datestr, secstodate);
  -        newsecs = parseHTTPdate(datestr);
  +        secstodate *= APR_USEC_PER_SEC;
  +        newsecs = apr_parseHTTPdate(datestr);
           if (secstodate == newsecs)
  -            printf("Yes %4d %11ld  %s\n", year, (long)secstodate, datestr);
  -        else if (newsecs == BAD_DATE)
  -            printf("No  %4d %11ld %11ld %s\n", year, (long)secstodate, 
  -                   (long)newsecs, datestr);
  +            printf("Yes %4d %19lld %s\n", year, secstodate, datestr);
  +        else if (newsecs == APR_DATE_BAD)
  +            printf("No  %4d %19lld %19lld %s\n", year, secstodate, 
  +                   newsecs, datestr);
           else
  -            printf("No* %4d %11ld %11ld %s\n", year, (long)secstodate, 
  -                   (long)newsecs, datestr);
  +            printf("No* %4d %19lld %19lld %s\n", year, secstodate, 
  +                   newsecs, datestr);
       }
       
       srand48(978245L);
  @@ -166,15 +171,16 @@
           if (guess < 0) guess *= -1;
           secstodate = guess + offset;
           gm_timestr_822(datestr, secstodate);
  -        newsecs = parseHTTPdate(datestr);
  +        secstodate *= APR_USEC_PER_SEC;
  +        newsecs = apr_parseHTTPdate(datestr);
           if (secstodate == newsecs)
  -            printf("Yes %11ld  %s\n", (long)secstodate, datestr);
  -        else if (newsecs == BAD_DATE)
  -            printf("No  %11ld %11ld %s\n", (long)secstodate, 
  -                   (long)newsecs, datestr);
  +            printf("Yes %" APR_TIME_T_FMT " %s\n", secstodate, datestr);
  +        else if (newsecs == APR_DATE_BAD)
  +            printf("No  %" APR_TIME_T_FMT " %" APR_TIME_T_FMT " %s\n", 
  +                   secstodate, newsecs, datestr);
           else
  -            printf("No* %11ld %11ld %s\n", (long)secstodate, 
  -                   (long)newsecs, datestr);
  +            printf("No* %" APR_TIME_T_FMT " %" APR_TIME_T_FMT " %s\n", 
  +                   secstodate, newsecs, datestr);
       }
       exit(0);
   }
  
  
  

Mime
View raw message