Re: Hi all
[notmuch-archives.git] / f8 / 5ba576851671662d6bce10e8b5153a6cc97dc7
1 Return-Path: <Vladimir.Marek@oracle.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 181C4431FD8\r
6         for <notmuch@notmuchmail.org>; Tue, 20 Aug 2013 02:29:33 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.299\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.299 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3, UNPARSEABLE_RELAY=0.001]\r
13         autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id 0ZogVAeX8MCZ for <notmuch@notmuchmail.org>;\r
17         Tue, 20 Aug 2013 02:29:25 -0700 (PDT)\r
18 Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 3BD46431FB6\r
22         for <notmuch@notmuchmail.org>; Tue, 20 Aug 2013 02:29:25 -0700 (PDT)\r
23 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94])\r
24         by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with\r
25         ESMTP id r7K9TEEn005178\r
26         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);\r
27         Tue, 20 Aug 2013 09:29:14 GMT\r
28 Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86])\r
29         by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
30         r7K9TAjf028078\r
31         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);\r
32         Tue, 20 Aug 2013 09:29:13 GMT\r
33 Received: from abhmt114.oracle.com (abhmt114.oracle.com [141.146.116.66])\r
34         by userz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
35         r7K9TAc3028059; Tue, 20 Aug 2013 09:29:10 GMT\r
36 Received: from tbd.cz.oracle.com (/10.163.101.124)\r
37         by default (Oracle Beehive Gateway v4.0)\r
38         with ESMTP ; Tue, 20 Aug 2013 02:29:10 -0700\r
39 From: Vladimir.Marek@oracle.com\r
40 To: notmuch@notmuchmail.org\r
41 Subject: [PATCH 4/4] timegm: add portable implementation (Solaris support)\r
42 Date: Tue, 20 Aug 2013 11:28:55 +0200\r
43 Message-Id: <1376990935-12411-1-git-send-email-Vladimir.Marek@oracle.com>\r
44 X-Mailer: git-send-email 1.7.9.2\r
45 In-Reply-To: <m2eh9sn8cm.fsf@guru.guru-group.fi>\r
46 References: <m2eh9sn8cm.fsf@guru.guru-group.fi>\r
47 X-Source-IP: ucsinet22.oracle.com [156.151.31.94]\r
48 Cc: Vladimir Marek <vlmarek@volny.cz>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Tue, 20 Aug 2013 09:29:33 -0000\r
62 \r
63 From: Blake Jones <blakej@foo.net>\r
64 \r
65 The timegm(3) function is a non-standard extension to libc which is\r
66 available in GNU libc and on some BSDs.  Although SunOS had this\r
67 function in its libc, Solaris (unfortunately) removed it.  This patch\r
68 implements a very simple version of timegm() which is good enough for\r
69 parse-time-string.c.\r
70 \r
71 Signed-off-by: Vladimir Marek <vlmarek@volny.cz>\r
72 ---\r
73  compat/Makefile.local                 |    4 +++\r
74  compat/compat.h                       |    5 +++\r
75  compat/have_timegm.c                  |    7 ++++\r
76  compat/timegm.c                       |   57 +++++++++++++++++++++++++++++++++\r
77  configure                             |   11 +++++++\r
78  parse-time-string/parse-time-string.c |    1 +\r
79  6 files changed, 85 insertions(+)\r
80  create mode 100644 compat/have_timegm.c\r
81  create mode 100644 compat/timegm.c\r
82 \r
83 diff --git a/compat/Makefile.local b/compat/Makefile.local\r
84 index 2c4f65f..b0d5417 100644\r
85 --- a/compat/Makefile.local\r
86 +++ b/compat/Makefile.local\r
87 @@ -17,4 +17,8 @@ ifneq ($(HAVE_STRSEP),1)\r
88  notmuch_compat_srcs += $(dir)/strsep.c\r
89  endif\r
90  \r
91 +ifneq ($(HAVE_TIMEGM),1)\r
92 +notmuch_compat_srcs += $(dir)/timegm.c\r
93 +endif\r
94 +\r
95  SRCS := $(SRCS) $(notmuch_compat_srcs)\r
96 diff --git a/compat/compat.h b/compat/compat.h\r
97 index ae762c3..5a402d5 100644\r
98 --- a/compat/compat.h\r
99 +++ b/compat/compat.h\r
100 @@ -57,6 +57,11 @@ char* strcasestr(const char *haystack, const char *needle);\r
101  char *strsep(char **stringp, const char *delim);\r
102  #endif /* !HAVE_STRSEP */\r
103  \r
104 +#if !HAVE_TIMEGM\r
105 +#include <time.h>\r
106 +time_t timegm (struct tm *tm);\r
107 +#endif /* !HAVE_TIMEGM */\r
108 +\r
109  /* Silence gcc warnings about unused results.  These warnings exist\r
110   * for a reason; any use of this needs to be justified. */\r
111  #ifdef __GNUC__\r
112 diff --git a/compat/have_timegm.c b/compat/have_timegm.c\r
113 new file mode 100644\r
114 index 0000000..b62b793\r
115 --- /dev/null\r
116 +++ b/compat/have_timegm.c\r
117 @@ -0,0 +1,7 @@\r
118 +#include <time.h>\r
119 +#include "compat.h"\r
120 +\r
121 +int main()\r
122 +{\r
123 +    return (int) timegm((struct tm *)0);\r
124 +}\r
125 diff --git a/compat/timegm.c b/compat/timegm.c\r
126 new file mode 100644\r
127 index 0000000..213963b\r
128 --- /dev/null\r
129 +++ b/compat/timegm.c\r
130 @@ -0,0 +1,57 @@\r
131 +/* timegm.c --- Implementation of replacement timegm function.\r
132 +   Copyright (C) 2012 Free Software Foundation, Inc.\r
133 +\r
134 +   This program is free software; you can redistribute it and/or\r
135 +   modify it under the terms of the GNU General Public License as\r
136 +   published by the Free Software Foundation; either version 3, or (at\r
137 +   your option) any later version.\r
138 +\r
139 +   This program is distributed in the hope that it will be useful, but\r
140 +   WITHOUT ANY WARRANTY; without even the implied warranty of\r
141 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
142 +   General Public License for more details.\r
143 +\r
144 +   You should have received a copy of the GNU General Public License\r
145 +   along with this program; if not, write to the Free Software\r
146 +   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\r
147 +   02110-1301, USA.  */\r
148 +\r
149 +/* Written by Blake Jones. */\r
150 +\r
151 +#include <time.h>\r
152 +#include "compat.h"\r
153 +\r
154 +static int\r
155 +leapyear (int year)\r
156 +{\r
157 +    return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));\r
158 +}\r
159 +\r
160 +/*\r
161 + * This is a simple implementation of timegm() which does what is needed\r
162 + * by create_output() -- just turns the "struct tm" into a GMT time_t.\r
163 + * It does not normalize any of the fields of the "struct tm", nor does\r
164 + * it set tm_wday or tm_yday.\r
165 + */\r
166 +time_t\r
167 +timegm (struct tm *tm)\r
168 +{\r
169 +    int        monthlen[2][12] = {\r
170 +       { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
171 +       { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
172 +    };\r
173 +    int        year, month, days;\r
174 +\r
175 +    days = 365 * (tm->tm_year - 70);\r
176 +    for (year = 70; year < tm->tm_year; year++) {\r
177 +       if (leapyear(1900 + year)) {\r
178 +           days++;\r
179 +       }\r
180 +    }\r
181 +    for (month = 0; month < tm->tm_mon; month++) {\r
182 +       days += monthlen[leapyear(1900 + year)][month];\r
183 +    }\r
184 +    days += tm->tm_mday - 1;\r
185 +\r
186 +    return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);\r
187 +}\r
188 diff --git a/configure b/configure\r
189 index ac44857..6166917 100755\r
190 --- a/configure\r
191 +++ b/configure\r
192 @@ -530,6 +530,17 @@ else\r
193  fi\r
194  rm -f compat/have_strsep\r
195  \r
196 +printf "Checking for timegm... "\r
197 +if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1\r
198 +then\r
199 +    printf "Yes.\n"\r
200 +    have_timegm="1"\r
201 +else\r
202 +    printf "No (will use our own instead).\n"\r
203 +    have_timegm="0"\r
204 +fi\r
205 +rm -f compat/have_timegm\r
206 +\r
207  printf "Checking for standard version of getpwuid_r... "\r
208  if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1\r
209  then\r
210 diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c\r
211 index 584067d..ccad422 100644\r
212 --- a/parse-time-string/parse-time-string.c\r
213 +++ b/parse-time-string/parse-time-string.c\r
214 @@ -32,6 +32,7 @@\r
215  #include <sys/time.h>\r
216  #include <sys/types.h>\r
217  \r
218 +#include "compat.h"\r
219  #include "parse-time-string.h"\r
220  \r
221  /*\r
222 -- \r
223 1.7.9.2\r
224 \r