List for cgit developers and users
 help / color / mirror / Atom feed
From: Jason at zx2c4.com (Jason A. Donenfeld)
Subject: [PATCH 2/2 v2] compat/timegm: new compat function for systems lacking timegm()
Date: Thu, 4 Apr 2013 16:13:04 +0200	[thread overview]
Message-ID: <CAHmME9oJuZy67Su6fGQ2LEpXQZr57pH5BpoR=iknCtH6oW+ntw@mail.gmail.com> (raw)
In-Reply-To: <20130401174758.GC2222@serenity.lan>

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.

Jason




  reply	other threads:[~2013-04-04 14:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-01 13:14 [PATCH 1/2] Makefile: re-include cgit.conf in cgit.mk john
2013-04-01 13:14 ` [PATCH 2/2] compat/timegm: new compat function for systems lacking timegm() john
2013-04-01 17:47   ` [PATCH 2/2 v2] " john
2013-04-04 14:13     ` Jason [this message]
2013-04-04 14:46       ` john
2013-04-04 14:59         ` Jason
2013-04-04 17:28           ` john

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHmME9oJuZy67Su6fGQ2LEpXQZr57pH5BpoR=iknCtH6oW+ntw@mail.gmail.com' \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).