diff options
Diffstat (limited to 'src/util/time.c')
-rw-r--r-- | src/util/time.c | 32 |
1 files changed, 31 insertions, 1 deletions
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 | */ | ||
723 | static time_t | ||
724 | my_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; |