[PATCH 2/2 v2] compat/timegm: new compat function for systems lacking timegm()

Jason A. Donenfeld Jason at zx2c4.com
Thu Apr 4 16:13:04 CEST 2013

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 <time.h>
>            #include <stdlib.h>
>            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.


More information about the CGit mailing list