Re: [PATCH v2] Omit User-Agent: header by default
[notmuch-archives.git] / 83 / ac1bf1602c588fb077f351c9510b37dd6a87d2
1 Return-Path: <blakej@foo.net>\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 4C880431FB6\r
6         for <notmuch@notmuchmail.org>; Mon,  5 Nov 2012 07:47:31 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 0yx8uOLeaIz7 for <notmuch@notmuchmail.org>;\r
16         Mon,  5 Nov 2012 07:47:30 -0800 (PST)\r
17 Received: from foo.net (70-36-235-136.dsl.static.sonic.net [70.36.235.136])\r
18         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 70D62431FAE\r
21         for <notmuch@notmuchmail.org>; Mon,  5 Nov 2012 07:47:30 -0800 (PST)\r
22 Received: from foo.net (localhost [127.0.0.1])\r
23         by foo.net (8.14.5+Sun/8.14.5) with ESMTP id qA5FlM1X002593;\r
24         Mon, 5 Nov 2012 07:47:22 -0800 (PST)\r
25 To: Tomi Ollila <tomi.ollila@iki.fi>\r
26 Subject: Re: [PATCH 10/10] timegm: add portable implementation (Solaris\r
27         support) \r
28 In-Reply-To: Your message of "Mon, 05 Nov 2012 14:09:33 +0200."\r
29         <m2txt4jloi.fsf@guru.guru-group.fi> \r
30 MIME-Version: 1.0\r
31 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"\r
32 Content-ID: <2591.1352130440.0@foo.net>\r
33 Date: Mon, 05 Nov 2012 07:47:22 -0800\r
34 Message-ID: <2592.1352130442@foo.net>\r
35 From: Blake Jones <blakej@foo.net>\r
36 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2\r
37         (foo.net [127.0.0.1]); Mon, 05 Nov 2012 07:47:22 -0800 (PST)\r
38 Cc: notmuch@notmuchmail.org\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.13\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43         <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Mon, 05 Nov 2012 15:47:31 -0000\r
52 \r
53 ------- =_aaaaaaaaaa0\r
54 Content-Type: text/plain; charset="us-ascii"\r
55 Content-ID: <2591.1352130440.1@foo.net>\r
56 \r
57 > Yet another idea for an alternative. Compile by entering 'sh xtimegm.c'\r
58 > and then run ./xtimegm\r
59\r
60 > Simple cases seems to work. Dst change may (or then may not) give one\r
61 > hour difference to the expected. The test "coverage" could be easily\r
62 > expanded to that ;)\r
63\r
64 > Hmm, I also found this:\r
65 > http://lists.gnu.org/archive/html/bug-gnulib/2003-09/msg00004.html\r
66 > which does 2 mktime's and one gmtime_r (without allocating tg!)...\r
67 > Pick any of these 3 -- or something different (e.g. less NIH if there is)\r
68 \r
69 Of these two, I would probably lean slightly toward the latter, in that\r
70 it relies more on libc for the time zone handling logic.\r
71 \r
72 But in general, this seems to me like a case where an explicit\r
73 implementation like mine is less prone to failure, because it doesn't\r
74 need to worry about time zones at all.  The other approaches rely on\r
75 letting libc do all the hard work of time zone manipulation, and then\r
76 reading the tea leaves to find a way to undo it.  I would guess that if\r
77 some change in the time standards is going to break one of these\r
78 implementations, it's going to be some new time zone specification, not\r
79 a change in the number of days in a month. :)\r
80 \r
81 For what it's worth, I used the attached program to test my\r
82 implementation, and it passed.\r
83 \r
84 Blake\r
85 \r
86 \r
87 ------- =_aaaaaaaaaa0\r
88 Content-Type: text/plain; charset="us-ascii"\r
89 Content-ID: <2591.1352130440.2@foo.net>\r
90 \r
91 #include <time.h>\r
92 \r
93 static int\r
94 leapyear(int year)\r
95 {\r
96         return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));\r
97 }\r
98 \r
99 /*\r
100  * This is a simple implementation of timegm() which does what is needed\r
101  * by parse-time-string.c -- just turns the "struct tm" into a GMT time_t.\r
102  * It does not normalize any of the fields of the "struct tm", nor does\r
103  * it set tm_wday or tm_yday.\r
104  */\r
105 static time_t\r
106 timegm(struct tm *tm)\r
107 {\r
108         int     monthlen[2][12] = {\r
109                 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
110                 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
111         };\r
112         int     year, month, days;\r
113 \r
114         days = 365 * (tm->tm_year - 70);\r
115         for (year = 70; year < tm->tm_year; year++) {\r
116                 if (leapyear(1900 + year)) {\r
117                         days++;\r
118                 }\r
119         }\r
120         for (month = 0; month < tm->tm_mon; month++) {\r
121                 days += monthlen[leapyear(1900 + year)][month];\r
122         }\r
123         days += tm->tm_mday - 1;\r
124 \r
125         return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 +\r
126             tm->tm_sec);\r
127 }\r
128 \r
129 #include <stdio.h>\r
130 #include <stdlib.h>\r
131 #include <unistd.h>\r
132 \r
133 void\r
134 tm_test(int niter)\r
135 {\r
136         const int       monthlen[2][12] = {\r
137                 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
138                 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
139         };\r
140         int             i;\r
141         struct tm       tm, *tmp;\r
142         time_t          t;\r
143 \r
144         for (i = 0; i < niter; i++) {\r
145                 tm.tm_year = (lrand48() % 67) + 70;\r
146                 tm.tm_mon = lrand48() % 12;\r
147                 do {\r
148                         t = (lrand48() % 31) + 1;\r
149                 } while (t > monthlen[leapyear(1900 + tm.tm_year)][tm.tm_mon]);\r
150                 tm.tm_mday = t;\r
151                 tm.tm_hour = lrand48() % 24;\r
152                 tm.tm_min = lrand48() % 60;\r
153                 tm.tm_sec = lrand48() % 60;\r
154 \r
155                 t = timegm(&tm);\r
156                 tmp = gmtime(&t);\r
157 \r
158                 if (tmp->tm_sec != tm.tm_sec ||\r
159                     tmp->tm_min != tm.tm_min ||\r
160                     tmp->tm_hour != tm.tm_hour ||\r
161                     tmp->tm_mday != tm.tm_mday ||\r
162                     tmp->tm_mon != tm.tm_mon ||\r
163                     tmp->tm_year != tm.tm_year) {\r
164                         printf("%4d-%02d-%02d %02d:%02d:%02d -> "\r
165                             "%4d-%02d-%02d %02d:%02d:%02d\n",\r
166                             tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,\r
167                             tm.tm_hour, tm.tm_min, tm.tm_sec,\r
168                             tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,\r
169                             tmp->tm_hour, tmp->tm_min, tmp->tm_sec);\r
170 \r
171                 }\r
172         }\r
173 }\r
174 \r
175 void\r
176 time_test(int niter)\r
177 {\r
178         int             i;\r
179         time_t          st, et;\r
180         struct tm       *tmp;\r
181 \r
182         for (i = 0; i < niter; i++) {\r
183                 st = (time_t)lrand48();\r
184 \r
185                 tmp = gmtime(&st);\r
186                 et = timegm(tmp);\r
187 \r
188                 if (st != et) {\r
189                         printf("%d -> %d (%4d-%02d-%02d %02d:%02d:%02d)\n",\r
190                             st, et,\r
191                             tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,\r
192                             tmp->tm_hour, tmp->tm_min, tmp->tm_sec);\r
193                 }\r
194         }\r
195 }\r
196 \r
197 int\r
198 main(void)\r
199 {\r
200         const int       niter = 10000000;\r
201 \r
202         srand48(getpid());\r
203 \r
204         tm_test(niter);\r
205         time_test(niter);\r
206 \r
207         return (0);\r
208 }\r
209 \r
210 ------- =_aaaaaaaaaa0--\r