apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/time/win32 time.c
Date Wed, 22 Jan 2003 19:11:02 GMT
wrowe       2003/01/22 11:11:02

  Modified:    time/win32 time.c
  Log:
    What an ugly patch.
  
    Reintroduce the broken is_dst exported value for Win9x/ME until a better
    solution is found.  This clears up a segfault for Win9x attempting to
    unpack times, while preserving the *good* behavior for WinNT in divining
    the correct DST flag.
  
  Revision  Changes    Path
  1.42      +77 -30    apr/time/win32/time.c
  
  Index: time.c
  ===================================================================
  RCS file: /home/cvs/apr/time/win32/time.c,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- time.c	10 Jan 2003 23:17:33 -0000	1.41
  +++ time.c	22 Jan 2003 19:11:02 -0000	1.42
  @@ -72,6 +72,7 @@
    */
   #define IsLeapYear(y) ((!(y % 4)) ? (((!(y % 400)) && (y % 100)) ? 1 : 0) : 0)
   
  +#if APR_HAS_UNICODE_FS
   static LPTIME_ZONE_INFORMATION GetLocalTimeZone()
   {
       static int init = 0;
  @@ -83,6 +84,7 @@
       }
       return &tz;
   }
  +#endif
   
   static void SystemTimeToAprExpTime(apr_time_exp_t *xt, SYSTEMTIME *tm)
   {
  @@ -169,40 +171,85 @@
   APR_DECLARE(apr_status_t) apr_time_exp_lt(apr_time_exp_t *result,
                                             apr_time_t input)
   {
  -    SYSTEMTIME st, localst;
  +    SYSTEMTIME st;
       FILETIME ft, localft;
  -    TIME_ZONE_INFORMATION *tz;
  -    apr_time_t localtime;
   
  -    tz = GetLocalTimeZone();
       AprTimeToFileTime(&ft, input);
  -    FileTimeToSystemTime(&ft, &st);
  -
  -    /* The Platform SDK documents that SYSTEMTIME/FILETIME are
  -     * generally UTC.  We use SystemTimeToTzSpecificLocalTime
  -     * because FileTimeToLocalFileFime is documented that the
  -     * resulting time local file time would have DST relative
  -     * to the *present* date, not the date converted.
  -     */
  -    SystemTimeToTzSpecificLocalTime(tz, &st, &localst);
  -    SystemTimeToAprExpTime(result, &localst);
  -    result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);
   
  -    /* Recover the resulting time as an apr time and use the
  -     * delta for gmtoff in seconds (and ignore msec rounding) 
  -     */
  -    SystemTimeToFileTime(&localst, &localft);
  -    FileTimeToAprTime(&localtime, &localft);
  -    result->tm_gmtoff = (int)apr_time_sec(localtime) 
  -                      - (int)apr_time_sec(input);
  -
  -    /* To compute the dst flag, we compare the expected 
  -     * local (standard) timezone bias to the delta.
  -     * [Note, in war time or double daylight time the
  -     * resulting tm_isdst is, desireably, 2 hours]
  -     */
  -    result->tm_isdst = (result->tm_gmtoff / 3600)
  -                     - (-(tz->Bias + tz->StandardBias) / 60);
  +#if APR_HAS_UNICODE_FS
  +    IF_WIN_OS_IS_UNICODE
  +    {
  +        SYSTEMTIME localst;
  +        apr_time_t localtime;
  +        TIME_ZONE_INFORMATION *tz;
  +
  +        tz = GetLocalTimeZone();
  +
  +        FileTimeToSystemTime(&ft, &st);
  +
  +        /* The Platform SDK documents that SYSTEMTIME/FILETIME are
  +         * generally UTC.  We use SystemTimeToTzSpecificLocalTime
  +         * because FileTimeToLocalFileFime is documented that the
  +         * resulting time local file time would have DST relative
  +         * to the *present* date, not the date converted.
  +         */
  +        SystemTimeToTzSpecificLocalTime(tz, &st, &localst);
  +        SystemTimeToAprExpTime(result, &localst);
  +        result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);
  +
  +
  +        /* Recover the resulting time as an apr time and use the
  +         * delta for gmtoff in seconds (and ignore msec rounding) 
  +         */
  +        SystemTimeToFileTime(&localst, &localft);
  +        FileTimeToAprTime(&localtime, &localft);
  +        result->tm_gmtoff = (int)apr_time_sec(localtime) 
  +                          - (int)apr_time_sec(input);
  +
  +        /* To compute the dst flag, we compare the expected 
  +         * local (standard) timezone bias to the delta.
  +         * [Note, in war time or double daylight time the
  +         * resulting tm_isdst is, desireably, 2 hours]
  +         */
  +        result->tm_isdst = (result->tm_gmtoff / 3600)
  +                         - (-(tz->Bias + tz->StandardBias) / 60);
  +    }
  +#endif
  +#if APR_HAS_ANSI_FS
  +    ELSE_WIN_OS_IS_ANSI
  +    {
  +	TIME_ZONE_INFORMATION tz;
  +
  +	/* XXX: This code is simply *wrong*.  The time converted will always
  +         * map to the *now current* status of daylight savings time.
  +         */
  +
  +        FileTimeToLocalFileTime(&ft, &localft);
  +        FileTimeToSystemTime(&localft, &st);
  +        SystemTimeToAprExpTime(result, &st, 1);
  +        result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);
  +
  +        switch (GetTimeZoneInformation(&tz)) {   
  +            case TIME_ZONE_ID_UNKNOWN:   
  +                xt->tm_isdst = 0;   
  +                /* Bias = UTC - local time in minutes   
  +                 * tm_gmtoff is seconds east of UTC   
  +                 */   
  +                xt->tm_gmtoff = tz.Bias * -60;   
  +                break;   
  +            case TIME_ZONE_ID_STANDARD:   
  +                xt->tm_isdst = 0;   
  +                xt->tm_gmtoff = (tz.Bias + tz.StandardBias) * -60;   
  +                break;   
  +            case TIME_ZONE_ID_DAYLIGHT:   
  +                xt->tm_isdst = 1;   
  +                xt->tm_gmtoff = (tz.Bias + tz.DaylightBias) * -60;   
  +                break;   
  +            default:   
  +                /* noop */;
  +        }   
  +    }
  +#endif
   
       return APR_SUCCESS;
   }
  
  
  

Mime
View raw message