Re: Avoiding the "huge INBOX of death"
[notmuch-archives.git] / 27 / 1740b52fbba49af7d52e34338e7ba8df11cd9c
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 24AC8431FAF\r
6         for <notmuch@notmuchmail.org>; Fri, 16 Aug 2013 07:38:56 -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 Jk7BGeocgUiZ for <notmuch@notmuchmail.org>;\r
17         Fri, 16 Aug 2013 07:38:49 -0700 (PDT)\r
18 Received: from userp1040.oracle.com (userp1040.oracle.com [156.151.31.81])\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 ABAB8429E2E\r
22         for <notmuch@notmuchmail.org>; Fri, 16 Aug 2013 07:38:49 -0700 (PDT)\r
23 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238])\r
24         by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with\r
25         ESMTP id r7GEcgFj004902\r
26         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);\r
27         Fri, 16 Aug 2013 14:38:43 GMT\r
28 Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231])\r
29         by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
30         r7GEcffA029802\r
31         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);\r
32         Fri, 16 Aug 2013 14:38:42 GMT\r
33 Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71])\r
34         by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
35         r7GEcfos029797; Fri, 16 Aug 2013 14:38:41 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 ; Fri, 16 Aug 2013 07:38:41 -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: Fri, 16 Aug 2013 16:38:17 +0200\r
43 Message-Id: <1376663897-24385-5-git-send-email-Vladimir.Marek@oracle.com>\r
44 X-Mailer: git-send-email 1.7.9.2\r
45 In-Reply-To: <1376663897-24385-1-git-send-email-Vladimir.Marek@oracle.com>\r
46 References: <1376663897-24385-1-git-send-email-Vladimir.Marek@oracle.com>\r
47 X-Source-IP: acsinet22.oracle.com [141.146.126.238]\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: Fri, 16 Aug 2013 14:38:56 -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                       |   37 +++++++++++++++++++++++++++++++++\r
77  configure                             |   11 ++++++++++\r
78  parse-time-string/parse-time-string.c |    1 +\r
79  6 files changed, 65 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..6d76164\r
128 --- /dev/null\r
129 +++ b/compat/timegm.c\r
130 @@ -0,0 +1,37 @@\r
131 +#include <time.h>\r
132 +#include "compat.h"\r
133 +\r
134 +static int\r
135 +leapyear (int year)\r
136 +{\r
137 +    return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));\r
138 +}\r
139 +\r
140 +/*\r
141 + * This is a simple implementation of timegm() which does what is needed\r
142 + * by create_output() -- just turns the "struct tm" into a GMT time_t.\r
143 + * It does not normalize any of the fields of the "struct tm", nor does\r
144 + * it set tm_wday or tm_yday.\r
145 + */\r
146 +time_t\r
147 +timegm (struct tm *tm)\r
148 +{\r
149 +    int        monthlen[2][12] = {\r
150 +       { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
151 +       { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
152 +    };\r
153 +    int        year, month, days;\r
154 +\r
155 +    days = 365 * (tm->tm_year - 70);\r
156 +    for (year = 70; year < tm->tm_year; year++) {\r
157 +       if (leapyear(1900 + year)) {\r
158 +           days++;\r
159 +       }\r
160 +    }\r
161 +    for (month = 0; month < tm->tm_mon; month++) {\r
162 +       days += monthlen[leapyear(1900 + year)][month];\r
163 +    }\r
164 +    days += tm->tm_mday - 1;\r
165 +\r
166 +    return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);\r
167 +}\r
168 diff --git a/configure b/configure\r
169 index ac44857..6166917 100755\r
170 --- a/configure\r
171 +++ b/configure\r
172 @@ -530,6 +530,17 @@ else\r
173  fi\r
174  rm -f compat/have_strsep\r
175  \r
176 +printf "Checking for timegm... "\r
177 +if ${CC} -o compat/have_timegm "$srcdir"/compat/have_timegm.c > /dev/null 2>&1\r
178 +then\r
179 +    printf "Yes.\n"\r
180 +    have_timegm="1"\r
181 +else\r
182 +    printf "No (will use our own instead).\n"\r
183 +    have_timegm="0"\r
184 +fi\r
185 +rm -f compat/have_timegm\r
186 +\r
187  printf "Checking for standard version of getpwuid_r... "\r
188  if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1\r
189  then\r
190 diff --git a/parse-time-string/parse-time-string.c b/parse-time-string/parse-time-string.c\r
191 index 584067d..ccad422 100644\r
192 --- a/parse-time-string/parse-time-string.c\r
193 +++ b/parse-time-string/parse-time-string.c\r
194 @@ -32,6 +32,7 @@\r
195  #include <sys/time.h>\r
196  #include <sys/types.h>\r
197  \r
198 +#include "compat.h"\r
199  #include "parse-time-string.h"\r
200  \r
201  /*\r
202 -- \r
203 1.7.9.2\r
204 \r