aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-01-07 22:22:48 +0100
committerChristian Grothoff <christian@grothoff.org>2021-01-07 22:22:48 +0100
commit4769344a7a8db5a9fecab394274b9407a14a2961 (patch)
tree926dfab1243f4d511fc1a13955180af59493fb31
parent5b10ad755f132e849ee35516fefe27df64eb188d (diff)
downloadgnunet-4769344a7a8db5a9fecab394274b9407a14a2961.tar.gz
gnunet-4769344a7a8db5a9fecab394274b9407a14a2961.zip
convert to GMT, not localtime in GNUNET_TIME_year_to_time
-rw-r--r--configure.ac2
-rw-r--r--src/util/time.c32
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
1538AC_HEADER_SYS_WAIT 1538AC_HEADER_SYS_WAIT
1539AC_TYPE_OFF_T 1539AC_TYPE_OFF_T
1540AC_TYPE_UID_T 1540AC_TYPE_UID_T
1541AC_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]) 1541AC_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])
1542 1542
1543# restore LIBS 1543# restore LIBS
1544LIBS=$SAVE_LIBS 1544LIBS=$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)
716} 716}
717 717
718 718
719#ifndef HAVE_TIMEGM
720/**
721 * As suggested in the timegm() man page.
722 */
723static time_t
724my_timegm (struct tm *tm)
725{
726 time_t ret;
727 char *tz;
728
729 tz = getenv ("TZ");
730 setenv ("TZ", "", 1);
731 tzset ();
732 ret = mktime (tm);
733 if (tz)
734 setenv ("TZ", tz, 1);
735 else
736 unsetenv ("TZ");
737 tzset ();
738 return ret;
739}
740
741
742#endif
743
744
719/** 745/**
720 * Convert a year to an expiration time of January 1st of that year. 746 * Convert a year to an expiration time of January 1st of that year.
721 * 747 *
@@ -740,7 +766,11 @@ GNUNET_TIME_year_to_time (unsigned int year)
740 t.tm_mon = 0; 766 t.tm_mon = 0;
741 t.tm_wday = 1; 767 t.tm_wday = 1;
742 t.tm_yday = 1; 768 t.tm_yday = 1;
743 tp = mktime (&t); 769#ifndef HAVE_TIMEGM
770 tp = my_timegm (&t);
771#else
772 tp = timegm (&t);
773#endif
744 GNUNET_break (tp != (time_t) -1); 774 GNUNET_break (tp != (time_t) -1);
745 ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */ 775 ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
746 return ret; 776 return ret;