From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 0D09B431FB6 for ; Tue, 20 Aug 2013 09:04:03 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] 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 7-nLPcIZgLx7 for ; Tue, 20 Aug 2013 09:03:53 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id CB75C431E62 for ; Tue, 20 Aug 2013 09:03:48 -0700 (PDT) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 12FB2100086; Tue, 20 Aug 2013 19:03:42 +0300 (EEST) From: Tomi Ollila To: Blake Jones , Vladimir.Marek@oracle.com Subject: Re: [PATCH 4/4] timegm: add portable implementation (Solaris support) In-Reply-To: <14321.1377012799@foo.net> References: <14321.1377012799@foo.net> User-Agent: Notmuch/0.16+3~g340c058 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain Cc: notmuch@notmuchmail.org, 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: Tue, 20 Aug 2013 16:04:03 -0000 On Tue, Aug 20 2013, Blake Jones wrote: >> 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. > > LGTM. > > Blake Thanks Blake for your quick answer to my (perhaps too quick) question. The copyright header gives FSF "owner"ship to the file -- which would be fine by the project -- but does assigning copyright to the FSF work like this... ... I started to look around and found (among other pages) this: http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=doc/Copyright/conditions.text;h=6e19adf0233900c9169e10fe7e0aa8d1feb73996;hb=HEAD Maybe for liability reasons FSF needs more than just stating the copyright at the beginning of file... I don't know -- but if this is the case maybe the easiest thing is to remove (amend) the Copyright line out of the file. In getline.c, and getdelim.c the code is taken from glibc. What I've understood this timegm.c is new art ? IMHO this uncertainty is the last thing preventing putting this series to the nmbug ready (to be pushed) queue... Tomi > >> Signed-off-by: Vladimir Marek >> --- >> compat/Makefile.local | 4 +++ >> compat/compat.h | 5 +++ >> compat/have_timegm.c | 7 ++++ >> compat/timegm.c | 57 +++++++++++++++++++++++++++++++++ >> configure | 11 +++++++ >> parse-time-string/parse-time-string.c | 1 + >> 6 files changed, 85 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..213963b >> --- /dev/null >> +++ b/compat/timegm.c >> @@ -0,0 +1,57 @@ >> +/* timegm.c --- Implementation of replacement timegm function. >> + Copyright (C) 2012 Free Software Foundation, Inc. >> + >> + This program is free software; you can redistribute it and/or >> + modify it under the terms of the GNU General Public License as >> + published by the Free Software Foundation; either version 3, or (at >> + your option) any later version. >> + >> + This program is distributed in the hope that it will be useful, but >> + WITHOUT ANY WARRANTY; without even the implied warranty of >> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> + General Public License for more details. >> + >> + You should have received a copy of the GNU General Public License >> + along with this program; if not, write to the Free Software >> + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA >> + 02110-1301, USA. */ >> + >> +/* Written by Blake Jones. */ >> + >> +#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 ac44857..6166917 100755 >> --- a/configure >> +++ b/configure >> @@ -530,6 +530,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 >> >> _______________________________________________ >> notmuch mailing list >> notmuch@notmuchmail.org >> http://notmuchmail.org/mailman/listinfo/notmuch >> > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch