[PATCH 4/4] timegm: add portable implementation (Solaris support)
authorVladimir.Marek <Vladimir.Marek@oracle.com>
Wed, 21 Aug 2013 11:09:54 +0000 (13:09 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:56:30 +0000 (09:56 -0800)
0e/08fdd1b9c5bb1eb64a2ac27bc24ea63957a315 [new file with mode: 0644]

diff --git a/0e/08fdd1b9c5bb1eb64a2ac27bc24ea63957a315 b/0e/08fdd1b9c5bb1eb64a2ac27bc24ea63957a315
new file mode 100644 (file)
index 0000000..5ea680c
--- /dev/null
@@ -0,0 +1,223 @@
+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 23A0B431FD4\r
+       for <notmuch@notmuchmail.org>; Wed, 21 Aug 2013 04:10:23 -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 4DcII5jOMO0k for <notmuch@notmuchmail.org>;\r
+       Wed, 21 Aug 2013 04:10:15 -0700 (PDT)\r
+Received: from userp1040.oracle.com (userp1040.oracle.com [156.151.31.81])\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 53F6D431FC2\r
+       for <notmuch@notmuchmail.org>; Wed, 21 Aug 2013 04:10:15 -0700 (PDT)\r
+Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94])\r
+       by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with\r
+       ESMTP id r7LBA74G024490\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);\r
+       Wed, 21 Aug 2013 11:10:07 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
+       r7LBA4sS001230\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);\r
+       Wed, 21 Aug 2013 11:10:06 GMT\r
+Received: from abhmt103.oracle.com (abhmt103.oracle.com [141.146.116.55])\r
+       by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+       r7LBA4QI000044; Wed, 21 Aug 2013 11:10:04 GMT\r
+Received: from tbd.cz.oracle.com (/10.163.101.124)\r
+       by default (Oracle Beehive Gateway v4.0)\r
+       with ESMTP ; Wed, 21 Aug 2013 04:10:04 -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: Wed, 21 Aug 2013 13:09:54 +0200\r
+Message-Id: <1377083394-29755-1-git-send-email-Vladimir.Marek@oracle.com>\r
+X-Mailer: git-send-email 1.7.9.2\r
+In-Reply-To: <m2eh9sn8cm.fsf@guru.guru-group.fi>\r
+References: <m2eh9sn8cm.fsf@guru.guru-group.fi>\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: Wed, 21 Aug 2013 11:10:23 -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                       |   56 +++++++++++++++++++++++++++++++++\r
+ configure                             |   11 +++++++\r
+ parse-time-string/parse-time-string.c |    1 +\r
+ 6 files changed, 84 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..a986887\r
+--- /dev/null\r
++++ b/compat/timegm.c\r
+@@ -0,0 +1,56 @@\r
++/* timegm.c --- Implementation of replacement timegm function.\r
++\r
++   This program is free software; you can redistribute it and/or\r
++   modify it under the terms of the GNU General Public License as\r
++   published by the Free Software Foundation; either version 3, or (at\r
++   your option) any later version.\r
++\r
++   This program is distributed in the hope that it will be useful, but\r
++   WITHOUT ANY WARRANTY; without even the implied warranty of\r
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++   General Public License for more details.\r
++\r
++   You should have received a copy of the GNU General Public License\r
++   along with this program; if not, write to the Free Software\r
++   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\r
++   02110-1301, USA.  */\r
++\r
++/* Written by Blake Jones. */\r
++\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 ac44857..6166917 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -530,6 +530,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