apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject cvs commit: apr/test testtime.c
Date Fri, 31 Aug 2001 06:07:34 GMT
jerenkrantz    01/08/30 23:07:34

  Modified:    .        CHANGES
               time/unix time.c
               misc/unix start.c
               test     testtime.c
  Added:       include/arch/unix internal_time.h
  Log:
  On platforms where neither HAVE_GMTOFF nor HAVE___OFFSET is defined,
  like Solaris, the function "get_offset" in apr/time/unix/time.c is a
  bottleneck in time formatting.
  
  On these platforms, get_offset ignores its argument; it really computes
  the server's offset from GMT, normalized so that it's independent of
  daylight savings.
  
  Here's a new version of the get_offset patch that initializes
  the TZ offset from apr_initialize.  I've attached the new include
  file that it uses, apr/include/arch/unix/internal_time.h
  
  --
  
  Justin added the missing call to apr_initialize in testtime.c so that
  testtime works on Solaris and produces the "right" output.
  
  Submitted by:	Brian Pane <bpane@pacbell.net>
  Reviewed by:	Justin Erenkrantz, Roy Fielding
  
  Revision  Changes    Path
  1.150     +4 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.149
  retrieving revision 1.150
  diff -u -r1.149 -r1.150
  --- CHANGES	2001/08/30 05:47:26	1.149
  +++ CHANGES	2001/08/31 06:07:34	1.150
  @@ -1,5 +1,9 @@
   Changes with APR b1  
   
  +  *) Cache GMT offset on platforms that don't store it in the tm struct.
  +     This offset is normalized to be independent of daylight savings
  +     time.  [Brian Pane <bpane@pacbell.net>]
  +
     *) Initial support for cygwin.  [Stipe Tolj <tolj@wapme-systems.de>]
   
     *) Fix a problem with buffered files on Unix.  [Brian Havard]
  
  
  
  1.1                  apr/include/arch/unix/internal_time.h
  
  Index: internal_time.h
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #ifndef TIME_INTERNAL_H
  #define TIME_INTERNAL_H
  
  #include "apr.h"
  
  void apr_unix_setup_time(void);
  
  #endif  /* TIME_INTERNAL_H */
  
  
  
  1.52      +52 -23    apr/time/unix/time.c
  
  Index: time.c
  ===================================================================
  RCS file: /home/cvs/apr/time/unix/time.c,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- time.c	2001/08/10 21:04:49	1.51
  +++ time.c	2001/08/31 06:07:34	1.52
  @@ -70,6 +70,10 @@
   #endif
   /* End System Headers */
   
  +#if !defined(HAVE_GMTOFF) && !defined(HAVE___OFFSET)
  +static apr_int32_t server_gmt_offset;
  +#endif /* if !defined(HAVE_GMTOFF) && !defined(HAVE___OFFSET) */
  +
   static apr_int32_t get_offset(struct tm *tm)
   {
   #ifdef HAVE_GMTOFF
  @@ -77,29 +81,7 @@
   #elif defined(HAVE___OFFSET)
       return tm->__tm_gmtoff;
   #else
  -    /* We don't have an offset field to use, so calculate it.
  -       mktime() is the inverse of localtime(); so, presumably,
  -       passing in a struct tm made by gmtime() let's us calculate
  -       the true GMT offset. However, there's a catch: if daylight
  -       savings is in effect, gmtime()will set the tm_isdst field
  -       and confuse mktime() into returning a time that's offset
  -       by one hour. In that case, we must adjust the calculated GMT
  -       offset. */
  -    {
  -        time_t t1 = time(0), t2 = 0;
  -        struct tm t;
  -        int was_dst;
  -
  -#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
  -        gmtime_r(&t1, &t);
  -#else
  -        t = *gmtime(&t1);
  -#endif
  -        was_dst = (t.tm_isdst > 0);
  -        t.tm_isdst = -1;
  -        t2 = mktime(&t);
  -        return (apr_int32_t) difftime(t1, t2) + (was_dst ? 3600 : 0);
  -    }
  +    return server_gmt_offset;
   #endif
   }
   
  @@ -308,3 +290,50 @@
     return APR_SUCCESS;
   }
   #endif
  +
  +APR_DECLARE(void) apr_unix_setup_time(void)
  +{
  +#if !defined(HAVE_GMTOFF) && !defined(HAVE___OFFSET)
  +    /* Precompute the offset from GMT on systems where it's not
  +       in struct tm.
  +
  +       Note: This offset is normalized to be independent of daylight
  +       savings time; if the calculation happens to be done in a
  +       time/place where a daylight savings adjustment is in effect,
  +       the returned offset has the same value that it would have
  +       in the same location if daylight savings were not in effect.
  +       The reason for this is that the returned offset can be
  +       applied to a past or future timestamp in explode_time(),
  +       so the DST adjustment obtained from the current time won't
  +       necessarily be applicable.
  +
  +       mktime() is the inverse of localtime(); so, presumably,
  +       passing in a struct tm made by gmtime() let's us calculate
  +       the true GMT offset. However, there's a catch: if daylight
  +       savings is in effect, gmtime()will set the tm_isdst field
  +       and confuse mktime() into returning a time that's offset
  +       by one hour. In that case, we must adjust the calculated GMT
  +       offset.
  +
  +     */
  +
  +    struct timeval now;
  +    time_t t1, t2;
  +    struct tm t;
  +    int was_dst;
  +
  +    gettimeofday(&now, NULL);
  +    t1 = now.tv_sec;
  +    t2 = 0;
  +
  +#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
  +    gmtime_r(&t1, &t);
  +#else
  +    t = *gmtime(&t1);
  +#endif
  +    was_dst = (t.tm_isdst > 0);
  +    t.tm_isdst = -1;
  +    t2 = mktime(&t);
  +    server_gmt_offset = (apr_int32_t) difftime(t1, t2) + (was_dst ? 3600 : 0);
  +#endif
  +}
  
  
  
  1.53      +2 -0      apr/misc/unix/start.c
  
  Index: start.c
  ===================================================================
  RCS file: /home/cvs/apr/misc/unix/start.c,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- start.c	2001/08/02 22:27:02	1.52
  +++ start.c	2001/08/31 06:07:34	1.53
  @@ -59,6 +59,7 @@
   
   #include "misc.h"       /* for WSAHighByte / WSALowByte */
   #include "locks.h"      /* for apr_unix_setup_lock() */
  +#include "internal_time.h"
   
   
   static int initialized = 0;
  @@ -83,6 +84,7 @@
   
   #if !defined(BEOS) && !defined(OS2) && !defined(WIN32) && !defined(NETWARE)
       apr_unix_setup_lock();
  +    apr_unix_setup_time();
   #elif defined WIN32 || defined(NETWARE)
       iVersionRequested = MAKEWORD(WSAHighByte, WSALowByte);
       err = WSAStartup((WORD) iVersionRequested, &wsaData);
  
  
  
  1.26      +2 -0      apr/test/testtime.c
  
  Index: testtime.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testtime.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- testtime.c	2001/08/01 21:06:26	1.25
  +++ testtime.c	2001/08/31 06:07:34	1.26
  @@ -73,6 +73,8 @@
       apr_int32_t hr_off = -5 * 3600; /* 5 hours in seconds */
       apr_int64_t hr_off_64;
   
  +    apr_initialize();
  +
       printf("APR Time Functions\n==================\n\n");
   
       STD_TEST_NEQ("Creating a pool to use", apr_pool_create(&p, NULL))
  
  
  

Mime
View raw message