List for cgit developers and users
 help / color / mirror / Atom feed
* Fwd: cgit: [PATCH] timegm() compat for non-Linux and non-BSD
       [not found] <CAEMywzqXUxSXRgV5biyU=3EAAk=oJE_dtWAj2RNWMN+Xd_fFZQ@mail.gmail.com>
@ 2016-02-23  2:15 ` Jason
  2016-02-23  2:15   ` Jason
  0 siblings, 1 reply; 5+ messages in thread
From: Jason @ 2016-02-23  2:15 UTC (permalink / raw)


---------- Forwarded message ----------
From: Brad Forschinger <bnjf at bnjf.id.au>
Date: Tue, Feb 23, 2016 at 12:27 AM
Subject: cgit: [PATCH] timegm() compat for non-Linux and non-BSD
To: Jason at zx2c4.com


Hi Jason,

I almost know that gmail will mangle the e-mail, so I'll include it as
an attachment.

Brad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-timegm-compat-for-non-Linux-and-non-BSD.patch
Type: text/x-diff
Size: 1407 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20160223/41a8a3e5/attachment.patch>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* cgit: [PATCH] timegm() compat for non-Linux and non-BSD
  2016-02-23  2:15 ` Fwd: cgit: [PATCH] timegm() compat for non-Linux and non-BSD Jason
@ 2016-02-23  2:15   ` Jason
  2016-02-23  2:15     ` Jason
  0 siblings, 1 reply; 5+ messages in thread
From: Jason @ 2016-02-23  2:15 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* cgit: [PATCH] timegm() compat for non-Linux and non-BSD
  2016-02-23  2:15   ` Jason
@ 2016-02-23  2:15     ` Jason
  2016-02-23  9:38       ` john
  0 siblings, 1 reply; 5+ messages in thread
From: Jason @ 2016-02-23  2:15 UTC (permalink / raw)


On Tue, Feb 23, 2016 at 3:15 AM, Jason A. Donenfeld <Jason at zx2c4.com> wrote:
> Subject: [PATCH] timegm() compat for non-Linux and non-BSD

What platform, specifically, do you have in mind?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* cgit: [PATCH] timegm() compat for non-Linux and non-BSD
  2016-02-23  2:15     ` Jason
@ 2016-02-23  9:38       ` john
  2016-02-23 14:32         ` Jason
  0 siblings, 1 reply; 5+ messages in thread
From: john @ 2016-02-23  9:38 UTC (permalink / raw)


On Tue, Feb 23, 2016 at 03:15:50AM +0100, Jason A. Donenfeld wrote:
> On Tue, Feb 23, 2016 at 3:15 AM, Jason A. Donenfeld <Jason at zx2c4.com> wrote:
> > Subject: [PATCH] timegm() compat for non-Linux and non-BSD
> 
> What platform, specifically, do you have in mind?

I know that Solaris doesn't have timegm().

However, if we're going to do this I'd prefer to use the compat
infrastructure version I posted a few years ago [1].  I recall that
(although it's recommented in the man page) the TZ option does have some
problems compared to the approach in my version but I can't remember
what they are off the top of my head.

[1] http://lists.zx2c4.com/pipermail/cgit/2013-April/001109.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

* cgit: [PATCH] timegm() compat for non-Linux and non-BSD
  2016-02-23  9:38       ` john
@ 2016-02-23 14:32         ` Jason
  0 siblings, 0 replies; 5+ messages in thread
From: Jason @ 2016-02-23 14:32 UTC (permalink / raw)


Thanks for posting that thread. I'd forgotten about that. I think my
views there are still solid:

We either use the hack from the manpage (which is what Brad's patch
does), or, so that we don't have to make compatibility infrastructure,
we simply work around this function so that we don't need it. Seeing
as it's only used in one place, I dont think this will be a problem.
I'll gladly accept a patch that fixes that.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-02-23 14:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAEMywzqXUxSXRgV5biyU=3EAAk=oJE_dtWAj2RNWMN+Xd_fFZQ@mail.gmail.com>
2016-02-23  2:15 ` Fwd: cgit: [PATCH] timegm() compat for non-Linux and non-BSD Jason
2016-02-23  2:15   ` Jason
2016-02-23  2:15     ` Jason
2016-02-23  9:38       ` john
2016-02-23 14:32         ` Jason

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).