httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject warning from irix 6.2 cc
Date Fri, 03 Jan 1997 06:40:31 GMT
cfe: Warning 851: util.c, line 109: constant initializer expression is
invalid (refers to automatic variables).
     struct tm gmt = *gmtime(&tt);
 ----^

Interesting.  I'd have to dig out my copy of the ansi c standard to see
if this is valid -- but I'm tempted to believe the compiler because this
is a structure initialization, not a scalar.  Patch included.

Someone should test with HAS_GMTOFF defined.

Dean

*** util.c.dist	Thu Jan  2 22:32:02 1997
--- util.c	Thu Jan  2 22:37:33 1997
***************
*** 103,127 ****
  }
  
  /* What a pain in the ass. */
  struct tm *get_gmtoff(int *tz) {
      time_t tt = time(NULL);
- #if !defined(HAS_GMTOFF)
-     struct tm gmt = *gmtime(&tt);
- #endif
      struct tm *t = localtime(&tt);
  
- #if defined(HAS_GMTOFF)
      *tz = (int) (t->tm_gmtoff / 60);
  #else
      /* Assume we are never more than 24 hours away. */
!     int days = t->tm_yday - gmt.tm_yday;
!     int hours = ((days < -1 ? 24 : 1 < days ? -24 : days * 24)
  		 + t->tm_hour - gmt.tm_hour);
!     int minutes = hours * 60 + t->tm_min - gmt.tm_min;
      *tz = minutes;
- #endif
      return t;
  }
  
  
  /* Match = 0, NoMatch = 1, Abort = -1 */
--- 103,134 ----
  }
  
  /* What a pain in the ass. */
+ #if defined(HAS_GMTOFF)
  struct tm *get_gmtoff(int *tz) {
      time_t tt = time(NULL);
      struct tm *t = localtime(&tt);
  
      *tz = (int) (t->tm_gmtoff / 60);
+     return t;
+ }
  #else
+ struct tm *get_gmtoff(int *tz) {
+     time_t tt = time(NULL);
+     struct tm gmt;
+     struct tm *t;
+     int days, hours, minutes;
+ 
      /* Assume we are never more than 24 hours away. */
!     gmt = *gmtime(&tt); /* remember gmtime/localtime return ptr to static */
!     t = localtime(&tt); /* buffer... so be careful */
!     days = t->tm_yday - gmt.tm_yday;
!     hours = ((days < -1 ? 24 : 1 < days ? -24 : days * 24)
  		 + t->tm_hour - gmt.tm_hour);
!     minutes = hours * 60 + t->tm_min - gmt.tm_min;
      *tz = minutes;
      return t;
  }
+ #endif
  
  
  /* Match = 0, NoMatch = 1, Abort = -1 */


Mime
View raw message