From 9a66a4329902cbcc34e15f2839017808d62f23f2 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Thu, 31 May 2007 06:44:07 +0000 Subject: [PATCH] Added support for checking timezone and tm_gmtoff. Fixed silc_time_msec. --- CHANGES | 7 ++++ configure.ad | 73 ++++++++++++++++++++++++++++++++++++++++- lib/silcutil/silctime.c | 45 ++++++++++++++++++------- 3 files changed, 113 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 454abdf2..5b7d41ec 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +Thu May 31 09:40:56 EEST 2007 Pekka Riikonen + + * 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 * Added silc-toolkit.spec.in RPM spec file. diff --git a/configure.ad b/configure.ad index c3b8b8f7..5bd10618 100644 --- a/configure.ad +++ b/configure.ad @@ -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 + #include + 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 + #include + 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 + #include + 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 + #include + 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) diff --git a/lib/silcutil/silctime.c b/lib/silcutil/silctime.c index 6dc321d6..3f3a2807 100644 --- a/lib/silcutil/silctime.c +++ b/lib/silcutil/silctime.c @@ -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; -- 2.24.0