From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason at zx2c4.com (Jason A. Donenfeld) Date: Thu, 4 Apr 2013 16:13:04 +0200 Subject: [PATCH 2/2 v2] compat/timegm: new compat function for systems lacking timegm() In-Reply-To: <20130401174758.GC2222@serenity.lan> References: <355839ae094873aef82ea1c8b7b7f9f7cc873b9c.1364821972.git.john@keeping.me.uk> <75a384665737f5f9a1768641bc673c91bfa7ebca.1364821972.git.john@keeping.me.uk> <20130401174758.GC2222@serenity.lan> Message-ID: Hi John, Is this strictly necessary? Would we be perhaps better off working around gmtime by using an alternative function all together? Or, if we do require a compat version, the man page suggests this much simpler alternative: > For a portable version of timegm(), set the TZ environment variable to UTC, call mktime(3) and restore the value of TZ. Something like > #include > #include > 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; > } This might not be entirely safe, were cgit to ever become multi-threaded, but it's certainly a lot simpler than rolling our own. Jason