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