From 4769344a7a8db5a9fecab394274b9407a14a2961 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 7 Jan 2021 22:22:48 +0100 Subject: convert to GMT, not localtime in GNUNET_TIME_year_to_time --- configure.ac | 2 +- src/util/time.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 530e38d88..eca988bb3 100644 --- a/configure.ac +++ b/configure.ac @@ -1538,7 +1538,7 @@ AC_FUNC_VPRINTF AC_HEADER_SYS_WAIT AC_TYPE_OFF_T AC_TYPE_UID_T -AC_CHECK_FUNCS([atoll stat64 strnlen mremap getrlimit setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid $funcstocheck getifaddrs freeifaddrs getresgid mallinfo malloc_size malloc_usable_size getrusage random srandom stat statfs statvfs wait4]) +AC_CHECK_FUNCS([atoll stat64 strnlen mremap getrlimit setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid $funcstocheck getifaddrs freeifaddrs getresgid mallinfo malloc_size malloc_usable_size getrusage random srandom stat statfs statvfs wait4 timegm]) # restore LIBS LIBS=$SAVE_LIBS diff --git a/src/util/time.c b/src/util/time.c index 5205fe11a..9e41305f1 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -716,6 +716,32 @@ GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at) } +#ifndef HAVE_TIMEGM +/** + * As suggested in the timegm() man page. + */ +static time_t +my_timegm (struct tm *tm) +{ + time_t ret; + char *tz; + + tz = getenv ("TZ"); + setenv ("TZ", "", 1); + tzset (); + ret = mktime (tm); + if (tz) + setenv ("TZ", tz, 1); + else + unsetenv ("TZ"); + tzset (); + return ret; +} + + +#endif + + /** * Convert a year to an expiration time of January 1st of that year. * @@ -740,7 +766,11 @@ GNUNET_TIME_year_to_time (unsigned int year) t.tm_mon = 0; t.tm_wday = 1; t.tm_yday = 1; - tp = mktime (&t); +#ifndef HAVE_TIMEGM + tp = my_timegm (&t); +#else + tp = timegm (&t); +#endif GNUNET_break (tp != (time_t) -1); ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */ return ret; -- cgit v1.2.3