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
__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)
{
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 */
{
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 */
SilcBool silc_time_value(SilcInt64 time_val, SilcTime ret_time)
{
- struct tm *time;
+ struct tm *t;
unsigned int msec = 0;
time_t timeval;
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 :
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;