List for cgit developers and users
 help / color / mirror / Atom feed
From: Jason at zx2c4.com (Jason A. Donenfeld)
Subject: cgit: [PATCH] timegm() compat for non-Linux and non-BSD
Date: Tue, 23 Feb 2016 03:15:28 +0100	[thread overview]
Message-ID: <CAHmME9pbpf3PJ4_fAy52w+94uP5tF6HUfwLVvV-oAUo8Otts9w@mail.gmail.com> (raw)
In-Reply-To: <CAHmME9oZ1fgE7+ffYjdbZ7FUKfmtfhkRRmO=xbvRdSZ_jzkyMg@mail.gmail.com>

From 34e1cfd7f56e20c577cebba31e8235e101f95972 Mon Sep 17 00:00:00 2001
From: Brad Forschinger <bnjf at users.noreply.github.com>
Date: Tue, 23 Feb 2016 10:18:34 +1100
Subject: [PATCH] timegm() compat for non-Linux and non-BSD

---
 cgit.mk    |  9 +++++++++
 ui-stats.c | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/cgit.mk b/cgit.mk
index 1b50307..4f75264 100644
--- a/cgit.mk
+++ b/cgit.mk
@@ -65,6 +65,15 @@ ifdef HAVE_LINUX_SENDFILE
  CGIT_CFLAGS += -DHAVE_LINUX_SENDFILE
 endif

+# from timegm(3): These functions are non-standard GNU extensions that
+# are also present on the BSDs. Avoid their use; see NOTES.
+ifeq ($(findstring BSD,$(uname_S)),BSD)
+ CGIT_CFLAGS += -DHAVE_TIMEGM
+endif
+ifeq ($(uname_S),Linux)
+ CGIT_CFLAGS += -DHAVE_TIMEGM
+endif
+
 CGIT_OBJ_NAMES += cgit.o
 CGIT_OBJ_NAMES += cache.o
 CGIT_OBJ_NAMES += cmd.o
diff --git a/ui-stats.c b/ui-stats.c
index 8cd9178..67b99aa 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -11,6 +11,25 @@ struct authorstat {
 #define DAY_SECS (60 * 60 * 24)
 #define WEEK_SECS (DAY_SECS * 7)

+#ifndef HAVE_TIMEGM
+time_t 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;
+}
+#endif
+
 static void trunc_week(struct tm *tm)
 {
  time_t t = timegm(tm);
-- 
2.4.3


  reply	other threads:[~2016-02-23  2:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAEMywzqXUxSXRgV5biyU=3EAAk=oJE_dtWAj2RNWMN+Xd_fFZQ@mail.gmail.com>
2016-02-23  2:15 ` Fwd: " Jason
2016-02-23  2:15   ` Jason [this message]
2016-02-23  2:15     ` Jason
2016-02-23  9:38       ` john
2016-02-23 14:32         ` Jason

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=CAHmME9pbpf3PJ4_fAy52w+94uP5tF6HUfwLVvV-oAUo8Otts9w@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).