1 Return-Path: <jani@nikula.org>
\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 0253A431FAF
\r
6 for <notmuch@notmuchmail.org>; Sun, 4 Nov 2012 02:21:04 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5
\r
12 tests=[HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 pmrY5ULl70g2 for <notmuch@notmuchmail.org>;
\r
16 Sun, 4 Nov 2012 02:21:03 -0800 (PST)
\r
17 Received: from mail-oa0-f53.google.com (mail-oa0-f53.google.com
\r
18 [209.85.219.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 046CD431FAE
\r
21 for <notmuch@notmuchmail.org>; Sun, 4 Nov 2012 02:21:02 -0800 (PST)
\r
22 Received: by mail-oa0-f53.google.com with SMTP id j6so5171694oag.26
\r
23 for <notmuch@notmuchmail.org>; Sun, 04 Nov 2012 02:21:02 -0800 (PST)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=mime-version:in-reply-to:references:date:message-id:subject:from:to
\r
27 :cc:content-type:x-gm-message-state;
\r
28 bh=zXSpgS3DMSzKlCOsj6qCbUDqK64q4wfMITJmEamc3zU=;
\r
29 b=epCEiDFpj5uOPRlHcg3XUPubgEI8yDb0b9jNpF3mBg6LNowsC5sPB2Wwaouwrw7Y8w
\r
30 lEjlm4N+Aic3G2zYkBCYtlVXreNQXT59jr7JJeBEGQoSib4DfcTLN+TPLi72e8ybx3/O
\r
31 XcEEjI8pntMCCFmS3E5ZYH9NIQJ/vOugAEas8Tof6cCwoQEN5aD4iz5UDpUcArL7pNJD
\r
32 EuXb8TOmKkB3acEM/N+U9WJkwiSaDPryMRZe7Mt6aq94YdTZMRNOCiJR96P7W2N+RMgD
\r
33 gbkZfNsXiQ0WKfBi/XNFmyPmKGjRxuKlcmgBiSzJyQZzhiwoRciGgSRp7g9Yo1pkwIMT
\r
36 Received: by 10.60.19.168 with SMTP id g8mr5235227oee.101.1352024461364; Sun,
\r
37 04 Nov 2012 02:21:01 -0800 (PST)
\r
38 Received: by 10.76.69.138 with HTTP; Sun, 4 Nov 2012 02:21:01 -0800 (PST)
\r
39 Received: by 10.76.69.138 with HTTP; Sun, 4 Nov 2012 02:21:01 -0800 (PST)
\r
40 In-Reply-To: <1351998962-25135-11-git-send-email-blakej@foo.net>
\r
41 References: <1351998962-25135-1-git-send-email-blakej@foo.net>
\r
42 <1351998962-25135-11-git-send-email-blakej@foo.net>
\r
43 Date: Sun, 4 Nov 2012 12:21:01 +0200
\r
45 <CAB+hUn-HBMnbrxQtn4E1RkKJa-wUEvm2HbdvtDxJGrv3jmtQdw@mail.gmail.com>
\r
46 Subject: Re: [PATCH 10/10] timegm: add portable implementation (Solaris
\r
48 From: Jani Nikula <jani@nikula.org>
\r
49 To: Blake Jones <blakej@foo.net>
\r
50 Content-Type: multipart/alternative; boundary=e89a8fb2062cbf4fcf04cda8b931
\r
52 ALoCoQn8vvIW7D7MKT4K4oUEILFZhdWQoLdHoC0rzjt/+cpov8pWrU3mjywLJxzGQbVepmLRh9xd
\r
53 Cc: notmuch@notmuchmail.org
\r
54 X-BeenThere: notmuch@notmuchmail.org
\r
55 X-Mailman-Version: 2.1.13
\r
57 List-Id: "Use and development of the notmuch mail system."
\r
58 <notmuch.notmuchmail.org>
\r
59 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
61 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
62 List-Post: <mailto:notmuch@notmuchmail.org>
\r
63 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
64 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
66 X-List-Received-Date: Sun, 04 Nov 2012 10:21:04 -0000
\r
68 --e89a8fb2062cbf4fcf04cda8b931
\r
69 Content-Type: text/plain; charset=UTF-8
\r
71 On Nov 4, 2012 11:30 AM, "Blake Jones" <blakej@foo.net> wrote:
\r
73 > The timegm(3) function is a non-standard extension to libc which is
\r
74 > available in GNU libc and on some BSDs. Although SunOS had this
\r
75 > function in its libc, Solaris (unfortunately) removed it. This patch
\r
76 > implements a very simple version of timegm() which is good enough for
\r
77 > parse-time-string.c.
\r
79 > Although notmuch's idiom for portability is to test for native
\r
80 > availability and put alternate versions in compat/, that approach led to
\r
81 > a compilation problem in this case. libnotmuch.a includes a call to
\r
82 > parse_time_string() from parse-time-vrp.o, and parse_time_string() in
\r
83 > libparse-time-string.a needs to call timegm(). An attempt to create
\r
84 > compat/timegm.c caused the link to fail, because libparse-time-string.a
\r
85 > acquired a dependency on the new timegm.o in libnotmuch.a, and the
\r
86 > linker only does a single pass on each ".a" looking for dependencies.
\r
87 > This seems to be the case both for the GNU linker and the Solaris
\r
88 > linker. A different possible workaround would have been to include
\r
89 > libnotmuch.a multiple times on the link line, but that seemed like a
\r
90 > brittle way to track this dependency.
\r
92 I'd prefer to use timegm() where available, and the suggested alternative
\r
93 [1] elsewhere. I'll look into the compat build issues when I have a moment.
\r
97 [1] http://www.kernel.org/doc/man-pages/online/pages/man3/timegm.3.html
\r
100 > parse-time-string/parse-time-string.c | 37
\r
101 ++++++++++++++++++++++++++++++++-
\r
102 > 1 file changed, 36 insertions(+), 1 deletion(-)
\r
104 > diff --git a/parse-time-string/parse-time-string.c
\r
105 b/parse-time-string/parse-time-string.c
\r
106 > index 584067d..28901af 100644
\r
107 > --- a/parse-time-string/parse-time-string.c
\r
108 > +++ b/parse-time-string/parse-time-string.c
\r
109 > @@ -1315,6 +1315,41 @@ fixup_ampm (struct state *state)
\r
114 > +leapyear (int year)
\r
116 > + return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
\r
120 > + * This is a simple implementation of timegm() which does what is needed
\r
121 > + * by create_output() -- just turns the "struct tm" into a GMT time_t.
\r
122 > + * It does not normalize any of the fields of the "struct tm", nor does
\r
123 > + * it set tm_wday or tm_yday.
\r
126 > +local_timegm (struct tm *tm)
\r
128 > + int monthlen[2][12] = {
\r
129 > + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
\r
130 > + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
\r
132 > + int year, month, days;
\r
134 > + days = 365 * (tm->tm_year - 70);
\r
135 > + for (year = 70; year < tm->tm_year; year++) {
\r
136 > + if (leapyear(1900 + year)) {
\r
140 > + for (month = 0; month < tm->tm_mon; month++) {
\r
141 > + days += monthlen[leapyear(1900 + year)][month];
\r
143 > + days += tm->tm_mday - 1;
\r
145 > + return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 +
\r
149 > /* Combine absolute and relative fields, and round. */
\r
151 > create_output (struct state *state, time_t *t_out, const time_t *ref,
\r
152 > @@ -1465,7 +1500,7 @@ create_output (struct state *state, time_t *t_out,
\r
154 > if (is_field_set (state, TM_TZ)) {
\r
155 > /* tm is in specified TZ, convert to UTC for timegm(3). */
\r
156 > tm.tm_min -= get_field (state, TM_TZ);
\r
157 > - t = timegm (&tm);
\r
158 > + t = local_timegm (&tm);
\r
160 > /* tm is in local time. */
\r
161 > t = mktime (&tm);
\r
165 > _______________________________________________
\r
166 > notmuch mailing list
\r
167 > notmuch@notmuchmail.org
\r
168 > http://notmuchmail.org/mailman/listinfo/notmuch
\r
170 --e89a8fb2062cbf4fcf04cda8b931
\r
171 Content-Type: text/html; charset=UTF-8
\r
172 Content-Transfer-Encoding: quoted-printable
\r
175 On Nov 4, 2012 11:30 AM, "Blake Jones" <<a href=3D"mailto:blak=
\r
176 ej@foo.net">blakej@foo.net</a>> wrote:<br>
\r
178 > The timegm(3) function is a non-standard extension to libc which is<br=
\r
180 > available in GNU libc and on some BSDs. =C2=A0Although SunOS had this<=
\r
182 > function in its libc, Solaris (unfortunately) removed it. =C2=A0This p=
\r
184 > implements a very simple version of timegm() which is good enough for<=
\r
186 > parse-time-string.c.<br>
\r
188 > Although notmuch's idiom for portability is to test for native<br>
\r
189 > availability and put alternate versions in compat/, that approach led =
\r
191 > a compilation problem in this case. =C2=A0libnotmuch.a includes a call=
\r
193 > parse_time_string() from parse-time-vrp.o, and parse_time_string() in<=
\r
195 > libparse-time-string.a needs to call timegm(). =C2=A0An attempt to cre=
\r
197 > compat/timegm.c caused the link to fail, because libparse-time-string.=
\r
199 > acquired a dependency on the new timegm.o in libnotmuch.a, and the<br>
\r
200 > linker only does a single pass on each ".a" looking for depe=
\r
202 > This seems to be the case both for the GNU linker and the Solaris<br>
\r
203 > linker. =C2=A0A different possible workaround would have been to inclu=
\r
205 > libnotmuch.a multiple times on the link line, but that seemed like a<b=
\r
207 > brittle way to track this dependency.</p>
\r
208 <p>I'd prefer to use timegm() where available, and the suggested altern=
\r
209 ative [1] elsewhere. I'll look into the compat build issues when I have=
\r
212 <p>[1] <a href=3D"http://www.kernel.org/doc/man-pages/online/pages/man3/tim=
\r
213 egm.3.html">http://www.kernel.org/doc/man-pages/online/pages/man3/timegm.3.=
\r
216 > =C2=A0parse-time-string/parse-time-string.c | =C2=A0 37 ++++++++++++++=
\r
217 ++++++++++++++++++-<br>
\r
218 > =C2=A01 file changed, 36 insertions(+), 1 deletion(-)<br>
\r
220 > diff --git a/parse-time-string/parse-time-string.c b/parse-time-string=
\r
221 /parse-time-string.c<br>
\r
222 > index 584067d..28901af 100644<br>
\r
223 > --- a/parse-time-string/parse-time-string.c<br>
\r
224 > +++ b/parse-time-string/parse-time-string.c<br>
\r
225 > @@ -1315,6 +1315,41 @@ fixup_ampm (struct state *state)<br>
\r
226 > =C2=A0 =C2=A0 =C2=A0return 0;<br>
\r
229 > +static int<br>
\r
230 > +leapyear (int year)<br>
\r
232 > + =C2=A0 =C2=A0return ((year % 4) =3D=3D 0 && ((year % 100) !=
\r
233 =3D 0 || (year % 400) =3D=3D 0));<br>
\r
237 > + * This is a simple implementation of timegm() which does what is nee=
\r
239 > + * by create_output() -- just turns the "struct tm" into a =
\r
241 > + * It does not normalize any of the fields of the "struct tm&quo=
\r
243 > + * it set tm_wday or tm_yday.<br>
\r
245 > +static time_t<br>
\r
246 > +local_timegm (struct tm *tm)<br>
\r
248 > + =C2=A0 =C2=A0int =C2=A0 =C2=A0 =C2=A0 =C2=A0monthlen[2][12] =3D {<br=
\r
250 > + =C2=A0 =C2=A0 =C2=A0 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3=
\r
252 > + =C2=A0 =C2=A0 =C2=A0 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3=
\r
254 > + =C2=A0 =C2=A0};<br>
\r
255 > + =C2=A0 =C2=A0int =C2=A0 =C2=A0 =C2=A0 =C2=A0year, month, days;<br>
\r
257 > + =C2=A0 =C2=A0days =3D 365 * (tm->tm_year - 70);<br>
\r
258 > + =C2=A0 =C2=A0for (year =3D 70; year < tm->tm_year; year++) {<b=
\r
260 > + =C2=A0 =C2=A0 =C2=A0 if (leapyear(1900 + year)) {<br>
\r
261 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 days++;<br>
\r
262 > + =C2=A0 =C2=A0 =C2=A0 }<br>
\r
263 > + =C2=A0 =C2=A0}<br>
\r
264 > + =C2=A0 =C2=A0for (month =3D 0; month < tm->tm_mon; month++) {<=
\r
266 > + =C2=A0 =C2=A0 =C2=A0 days +=3D monthlen[leapyear(1900 + year)][month=
\r
268 > + =C2=A0 =C2=A0}<br>
\r
269 > + =C2=A0 =C2=A0days +=3D tm->tm_mday - 1;<br>
\r
271 > + =C2=A0 =C2=A0return ((((days * 24) + tm->tm_hour) * 60 + tm->t=
\r
272 m_min) * 60 + tm->tm_sec);<br>
\r
275 > =C2=A0/* Combine absolute and relative fields, and round. */<br>
\r
276 > =C2=A0static int<br>
\r
277 > =C2=A0create_output (struct state *state, time_t *t_out, const time_t =
\r
279 > @@ -1465,7 +1500,7 @@ create_output (struct state *state, time_t *t_ou=
\r
280 t, const time_t *ref,<br>
\r
281 > =C2=A0 =C2=A0 =C2=A0if (is_field_set (state, TM_TZ)) {<br>
\r
282 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* tm is in specified TZ, convert to UTC f=
\r
283 or timegm(3). */<br>
\r
284 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 tm.tm_min -=3D get_field (state, TM_TZ);<b=
\r
286 > - =C2=A0 =C2=A0 =C2=A0 t =3D timegm (&tm);<br>
\r
287 > + =C2=A0 =C2=A0 =C2=A0 t =3D local_timegm (&tm);<br>
\r
288 > =C2=A0 =C2=A0 =C2=A0} else {<br>
\r
289 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* tm is in local time. */<br>
\r
290 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 t =3D mktime (&tm);<br>
\r
294 > _______________________________________________<br>
\r
295 > notmuch mailing list<br>
\r
296 > <a href=3D"mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a>=
\r
298 > <a href=3D"http://notmuchmail.org/mailman/listinfo/notmuch">http://not=
\r
299 muchmail.org/mailman/listinfo/notmuch</a><br>
\r
302 --e89a8fb2062cbf4fcf04cda8b931--
\r