Added support for checking timezone and tm_gmtoff. Fixed silc.toolkit.1.1
authorPekka Riikonen <priikone@silcnet.org>
Thu, 31 May 2007 06:44:07 +0000 (06:44 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 31 May 2007 06:44:07 +0000 (06:44 +0000)
silc_time_msec.

CHANGES
configure.ad
lib/silcutil/silctime.c

diff --git a/CHANGES b/CHANGES
index 454abdf23f346916595710649924ed67907507db..5b7d41ec6c4ab324946e6d738aecc01a36297f6a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+Thu May 31 09:40:56 EEST 2007  Pekka Riikonen <priikone@silcnet.org>
+
+       * SILC Toolkit 1.1.
+
+       * Added support for checking for timezone and tm_gmtoff.
+         Affected files are configure.ad and lib/silcutil/silctime.c.
+
 Wed May 30 18:46:34 EEST 2007  Pekka Riikonen <priikone@silcnet.org>
 
        * Added silc-toolkit.spec.in RPM spec file.
index c3b8b8f794019e7b8989fae08298c2de21d097df..5bd10618dee4039f3cd4e6a8cbcda134f4cae371 100644 (file)
@@ -182,7 +182,7 @@ AC_CHECK_FUNCS(poll select listen bind shutdown close connect setsockopt)
 AC_CHECK_FUNCS(setrlimit time ctime utime gettimeofday getrusage)
 AC_CHECK_FUNCS(chmod fcntl stat fstat getenv putenv strerror)
 AC_CHECK_FUNCS(getpid getgid getsid getpgid getpgrp getuid sched_yield)
-AC_CHECK_FUNCS(setgroups initgroups nl_langinfo nanosleep tzset)
+AC_CHECK_FUNCS(setgroups initgroups nl_langinfo nanosleep gmtime)
 AC_CHECK_FUNCS(strchr snprintf strstr strcpy strncpy memcpy memset memmove)
 
 # lib/contrib conditionals
@@ -1162,6 +1162,77 @@ if test x$has_threads = xtrue; then
   __SILC_HAVE_PTHREAD="#define __SILC_HAVE_PTHREAD 1"
 fi
 
+#
+# Check for timezone and tm_gmtoff for timezone information
+#
+AC_MSG_CHECKING(whether system has timezone)
+AC_RUN_IFELSE(
+  [
+    #include <stdio.h>
+    #include <time.h>
+    int main()
+    {
+      timezone = 0;
+      return 0;
+    }
+  ],
+  [ AC_MSG_RESULT(yes)
+    AC_DEFINE([HAVE_TIMEZONE], [], [HAVE_TIMEZONE]) ],
+  [ AC_MSG_RESULT(no) ],
+  [ AC_MSG_RESULT(no) ]
+)
+AC_MSG_CHECKING(whether system has tm_gmtoff)
+AC_RUN_IFELSE(
+  [
+    #include <stdio.h>
+    #include <time.h>
+    int main()
+    {
+      struct tm tm;
+      tm.tm_gmtoff = 0;
+      return 0;
+    }
+  ],
+  [ AC_MSG_RESULT(yes)
+    AC_DEFINE([HAVE_TM_GMTOFF], [], [HAVE_TM_GMTOFF]) ],
+  [ AC_MSG_RESULT(no) ],
+  [ AC_MSG_RESULT(no) ]
+)
+AC_MSG_CHECKING(whether system has __tm_gmtoff)
+AC_RUN_IFELSE(
+  [
+    #include <stdio.h>
+    #include <time.h>
+    int main()
+    {
+      struct tm tm;
+      tm.__tm_gmtoff = 0;
+      return 0;
+    }
+  ],
+  [ AC_MSG_RESULT(yes)
+    AC_DEFINE([HAVE___TM_GMTOFF], [], [HAVE___TM_GMTOFF]) ],
+  [ AC_MSG_RESULT(no) ],
+  [ AC_MSG_RESULT(no) ]
+)
+AC_MSG_CHECKING(whether system has __tm_gmtoff__)
+AC_RUN_IFELSE(
+  [
+    #include <stdio.h>
+    #include <time.h>
+    int main()
+    {
+      struct tm tm;
+      tm.__tm_gmtoff__ = 0;
+      return 0;
+    }
+  ],
+  [ AC_MSG_RESULT(yes)
+    AC_DEFINE([HAVE___TM_GMTOFF__], [], [HAVE___TM_GMTOFF__]) ],
+  [ AC_MSG_RESULT(no) ],
+  [ AC_MSG_RESULT(no) ]
+)
+
 # Native WIN32 compilation under cygwin
 #
 AC_MSG_CHECKING(whether to compile native WIN32 code)
index 6dc321d690b56e4875afdcc6f93eec07ab1fa337..3f3a2807fea4437569271eb3203b485bbfd6daae 100644 (file)
@@ -69,7 +69,8 @@ SilcInt64 silc_time_msec(void)
 {
   struct timeval curtime;
   silc_gettimeofday(&curtime);
-  return (curtime.tv_sec * 1000) + (curtime.tv_usec / 1000);
+  return (curtime.tv_sec * (SilcUInt64)1000) +
+    (curtime.tv_usec / (SilcUInt64)1000);
 }
 
 /* Return time since Epoch in microseconds */
@@ -78,7 +79,7 @@ SilcInt64 silc_time_usec(void)
 {
   struct timeval curtime;
   silc_gettimeofday(&curtime);
-  return (curtime.tv_sec * 1000000) + curtime.tv_usec;
+  return (curtime.tv_sec * (SilcUInt64)1000000) + curtime.tv_usec;
 }
 
 /* Returns time as string */
@@ -104,7 +105,7 @@ const char *silc_time_string(SilcInt64 time_val)
 
 SilcBool silc_time_value(SilcInt64 time_val, SilcTime ret_time)
 {
-  struct tm *time;
+  struct tm *t;
   unsigned int msec = 0;
   time_t timeval;
 
@@ -117,17 +118,18 @@ SilcBool silc_time_value(SilcInt64 time_val, SilcTime ret_time)
   msec = (SilcUInt64)time_val % (SilcUInt64)1000;
   timeval = (time_t)((SilcUInt64)time_val / (SilcUInt64)1000);
 
-  time = localtime(&timeval);
-  if (!time)
+  t = localtime(&timeval);
+  if (!t)
     return FALSE;
 
   memset(ret_time, 0, sizeof(*ret_time));
-  if (!silc_time_fill(ret_time, time->tm_year + 1900, time->tm_mon + 1,
-                     time->tm_mday, time->tm_hour, time->tm_min,
-                     time->tm_sec, msec))
+  if (!silc_time_fill(ret_time, t->tm_year + 1900, t->tm_mon + 1,
+                     t->tm_mday, t->tm_hour, t->tm_min,
+                     t->tm_sec, msec))
     return FALSE;
 
-  ret_time->dst        = time->tm_isdst ? 1 : 0;
+  ret_time->dst        = t->tm_isdst ? 1 : 0;
+
 #ifdef SILC_WIN32
   ret_time->utc_east   = _timezone < 0 ? 1 : 0;
   ret_time->utc_hour   = (ret_time->utc_east ? (-(_timezone)) / 3600 :
@@ -135,13 +137,34 @@ SilcBool silc_time_value(SilcInt64 time_val, SilcTime ret_time)
   ret_time->utc_minute = (ret_time->utc_east ? (-(_timezone)) % 3600 :
                          _timezone % 3600);
 #else
-#if defined(HAVE_TZSET)
+#if defined(HAVE_TIMEZONE)
   ret_time->utc_east   = timezone < 0 ? 1 : 0;
+#elif defined(HAVE_TM_GMTOFF)
+  ret_time->utc_east   = t->tm_gmtoff > 0 ? 1 : 0;
+#elif defined(HAVE___TM_GMTOFF)
+  ret_time->utc_east   = t->__tm_gmtoff > 0 ? 1 : 0;
+#elif defined(HAVE___TM_GMTOFF__)
+  ret_time->utc_east   = t->__tm_gmtoff__ > 0 ? 1 : 0;
+#endif /* HAVE_TIMEZONE */
+
+#if defined(HAVE_TIMEZONE)
   ret_time->utc_hour   = (ret_time->utc_east ? (-(timezone)) / 3600 :
                          timezone / 3600);
+  if (ret_time->dst)
+    ret_time->utc_hour++;
   ret_time->utc_minute = (ret_time->utc_east ? (-(timezone)) % 3600 :
                          timezone % 3600);
-#endif /* HAVE_TZSET */
+#elif defined(HAVE_GMTIME)
+  t = gmtime(&timeval);
+  if (t) {
+    ret_time->utc_hour   = (ret_time->utc_east
+                           ? ret_time->hour - t->tm_hour
+                           : ret_time->hour + t->tm_hour);
+    ret_time->utc_minute = (ret_time->utc_east
+                           ? ret_time->minute - t->tm_min
+                           : ret_time->minute + t->tm_min);
+  }
+#endif /* HAVE_TIMEZONE */
 #endif /* SILC_WIN32 */
 
   return TRUE;