[PATCH 4/4] timegm: add portable implementation (Solaris support)
authorVladimir.Marek <Vladimir.Marek@oracle.com>
Mon, 6 May 2013 15:16:02 +0000 (17:16 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:54:39 +0000 (09:54 -0800)
ec/10afa630decb3e28cdb24a9d245a3f198fa5bd [new file with mode: 0644]

diff --git a/ec/10afa630decb3e28cdb24a9d245a3f198fa5bd b/ec/10afa630decb3e28cdb24a9d245a3f198fa5bd
new file mode 100644 (file)
index 0000000..43195d5
--- /dev/null
@@ -0,0 +1,204 @@
+Return-Path: <Vladimir.Marek@oracle.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id AFC86431FDE\r
+       for <notmuch@notmuchmail.org>; Mon,  6 May 2013 08:16:53 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.299\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.299 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3, UNPARSEABLE_RELAY=0.001]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id tF-uai-zurWs for <notmuch@notmuchmail.org>;\r
+       Mon,  6 May 2013 08:16:52 -0700 (PDT)\r
+Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 9FD58431FC4\r
+       for <notmuch@notmuchmail.org>; Mon,  6 May 2013 08:16:37 -0700 (PDT)\r
+Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94])\r
+       by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with\r
+       ESMTP id r46FGUWf010046\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);\r
+       Mon, 6 May 2013 15:16:31 GMT\r
+Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231])\r
+       by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+       r46FGTUV012197\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL);\r
+       Mon, 6 May 2013 15:16:30 GMT\r
+Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71])\r
+       by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+       r46FGTvU003924; Mon, 6 May 2013 15:16:29 GMT\r
+Received: from vi64-x3-2e-prg06.cz.oracle.com (/10.163.102.127)\r
+       by default (Oracle Beehive Gateway v4.0)\r
+       with ESMTP ; Mon, 06 May 2013 08:16:28 -0700\r
+From: Vladimir.Marek@oracle.com\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/4] timegm: add portable implementation (Solaris support)\r
+Date: Mon,  6 May 2013 17:16:02 +0200\r
+Message-Id: <1367853362-11846-5-git-send-email-Vladimir.Marek@oracle.com>\r
+X-Mailer: git-send-email 1.7.9.2\r
+In-Reply-To: <1367853362-11846-1-git-send-email-Vladimir.Marek@oracle.com>\r
+References: <1367853362-11846-1-git-send-email-Vladimir.Marek@oracle.com>\r
+X-Source-IP: ucsinet22.oracle.com [156.151.31.94]\r
+Cc: Vladimir Marek <vlmarek@volny.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 06 May 2013 15:16:53 -0000\r
+\r
+From: Blake Jones <blakej@foo.net>\r
+\r
+The timegm(3) function is a non-standard extension to libc which is\r
+available in GNU libc and on some BSDs.  Although SunOS had this\r
+function in its libc, Solaris (unfortunately) removed it.  This patch\r
+implements a very simple version of timegm() which is good enough for\r
+parse-time-string.c.\r
+\r
+Signed-off-by: Vladimir Marek <vlmarek@volny.cz>\r
+---\r
+ compat/Makefile.local                 |    4 ++++\r
+ compat/compat.h                       |    5 +++++\r
+ compat/have_timegm.c                  |    7 +++++++\r
+ compat/timegm.c                       |   37 +++++++++++++++++++++++++++++++++\r
+ configure                             |   11 ++++++++++\r
+ parse-time-string/parse-time-string.c |    1 +\r
+ 6 files changed, 65 insertions(+)\r
+ create mode 100644 compat/have_timegm.c\r
+ create mode 100644 compat/timegm.c\r
+\r
+diff --git a/compat/Makefile.local b/compat/Makefile.local\r
+index 2c4f65f..b0d5417 100644\r
+--- a/compat/Makefile.local\r
++++ b/compat/Makefile.local\r
+@@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)\r
+ notmuch_compat_srcs += $(dir)/strsep.c\r
+ endif\r
\r
++ifneq ($(HAVE_TIMEGM),1)\r
++notmuch_compat_srcs += $(dir)/timegm.c\r
++endif\r
++\r
+ SRCS := $(SRCS) $(notmuch_compat_srcs)\r
+diff --git a/compat/compat.h b/compat/compat.h\r
+index ae762c3..5a402d5 100644\r
+--- a/compat/compat.h\r
++++ b/compat/compat.h\r
+@@ -57,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);\r
+ char *strsep(char **stringp, const char *delim);\r
+ #endif /* !HAVE_STRSEP */\r
\r
++#if !HAVE_TIMEGM\r
++#include <time.h>\r
++time_t timegm (struct tm *tm);\r
++#endif /* !HAVE_TIMEGM */\r
++\r
+ /* Silence gcc warnings about unused results.  These warnings exist\r
+  * for a reason; any use of this needs to be justified. */\r
+ #ifdef __GNUC__\r
+diff --git a/compat/have_timegm.c b/compat/have_timegm.c\r
+new file mode 100644\r
+index 0000000..b62b793\r
+--- /dev/null\r
++++ b/compat/have_timegm.c\r
+@@ -0,0 +1,7 @@\r
++#include <time.h>\r
++#include "compat.h"\r
++\r
++int main()\r
++{\r
++    return (int) timegm((struct tm *)0);\r
++}\r
+diff --git a/compat/timegm.c b/compat/timegm.c\r
+new file mode 100644\r
+index 0000000..6d76164\r
+--- /dev/null\r
++++ b/compat/timegm.c\r
+@@ -0,0 +1,37 @@\r
++#include <time.h>\r
++#include "compat.h"\r
++\r
++static int\r
++leapyear (int year)\r
++{\r
++    return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));\r
++}\r
++\r
++/*\r
++ * This is a simple implementation of timegm() which does what is needed\r
++ * by create_output() -- just turns the "struct tm" into a GMT time_t.\r
++ * It does not normalize any of the fields of the "struct tm", nor does\r
++ * it set tm_wday or tm_yday.\r
++ */\r
++time_t\r
++timegm (struct tm *tm)\r
++{\r
++    int       monthlen[2][12] = {\r
++      { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
++      { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
++    };\r
++    int       year, month, days;\r
++\r
++    days = 365 * (tm->tm_year - 70);\r
++    for (year = 70; year < tm->tm_year; year++) {\r
++      if (leapyear(1900 + year)) {\r
++          days++;\r
++      }\r
++    }\r
++    for (month = 0; month < tm->tm_mon; month++) {\r
++      days += monthlen[leapyear(1900 + year)][month];\r
++    }\r
++    days += tm->tm_mday - 1;\r
++\r
++    return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);\r
++}\r
+diff --git a/configure b/configure\r
+index 5243cac..ee037d8 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -528,6 +528,17 @@ else\r
+ fi\r
+ rm -f compat/have_strsep\r
\r
++printf "Checking for timegm... "\r
++if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1\r
++then\r
++    printf "Yes.\n"\r
++    have_timegm="1"\r
++else\r
++    printf "No (will use our own instead).\n"\r
++    have_timegm="0"\r
++fi\r
++rm -f compat/have_timegm\r
++\r
+ printf "Checking for standard version of getpwuid_r... "\r
+ if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1\r
+ then\r
+diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c\r
+index 584067d..ccad422 100644\r
+--- a/parse-time-string/parse-time-string.c\r
++++ b/parse-time-string/parse-time-string.c\r
+@@ -32,6 +32,7 @@\r
+ #include <sys/time.h>\r
+ #include <sys/types.h>\r
\r
++#include "compat.h"\r
+ #include "parse-time-string.h"\r
\r
+ /*\r
+-- \r
+1.7.9.2\r
+\r