1 Return-Path: <tomi.ollila@iki.fi>
\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 322CE431FB6
\r
6 for <notmuch@notmuchmail.org>; Mon, 5 Nov 2012 04:09:35 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 B6OED79nH9wW for <notmuch@notmuchmail.org>;
\r
16 Mon, 5 Nov 2012 04:09:34 -0800 (PST)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 0B550431FAE
\r
19 for <notmuch@notmuchmail.org>; Mon, 5 Nov 2012 04:09:34 -0800 (PST)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id 98973100094;
\r
22 Mon, 5 Nov 2012 14:09:33 +0200 (EET)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: Blake Jones <blakej@foo.net>, Jani Nikula <jani@nikula.org>
\r
25 Subject: Re: [PATCH 10/10] timegm: add portable implementation (Solaris
\r
27 In-Reply-To: <12349.1352043650@foo.net>
\r
28 References: <12349.1352043650@foo.net>
\r
29 User-Agent: Notmuch/0.14+81~gb8371cd (http://notmuchmail.org) Emacs/24.2.1
\r
30 (x86_64-unknown-linux-gnu)
\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
32 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
33 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
34 Date: Mon, 05 Nov 2012 14:09:33 +0200
\r
35 Message-ID: <m2txt4jloi.fsf@guru.guru-group.fi>
\r
37 Content-Type: multipart/mixed; boundary="=-=-="
\r
38 Cc: notmuch@notmuchmail.org
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\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 12:09:35 -0000
\r
54 Content-Type: text/plain
\r
56 On Sun, Nov 04 2012, Blake Jones wrote:
\r
60 >> I'd prefer to use timegm() where available, and the suggested
\r
61 >> alternative [1] elsewhere.
\r
63 >> [1] http://www.kernel.org/doc/man-pages/online/pages/man3/timegm.3.html
\r
65 > I considered this alternative, but decided against it because it's
\r
66 > completely MT-unsafe. I don't know whether libnotmuch itself is
\r
67 > MT-safe, but a process which called this routine in one thread would
\r
68 > temporarily throw off any timezone-related work that any other threads
\r
69 > were doing, even if they weren't using libnotmuch.
\r
71 Yet another idea for an alternative. Compile by entering 'sh xtimegm.c'
\r
72 and then run ./xtimegm
\r
74 Simple cases seems to work. Dst change may (or then may not) give one
\r
75 hour difference to the expected. The test "coverage" could be easily
\r
78 Hmm, I also found this:
\r
79 http://lists.gnu.org/archive/html/bug-gnulib/2003-09/msg00004.html
\r
80 which does 2 mktime's and one gmtime_r (without allocating tg!)...
\r
81 Pick any of these 3 -- or something different (e.g. less NIH if there is)
\r
90 Content-Type: text/plain; charset=utf-8
\r
91 Content-Disposition: inline; filename=xtimegm.c
\r
92 Content-Transfer-Encoding: quoted-printable
\r
93 Content-Description: yet another attempt for timegm() implementation
\r
95 #if 0 /* -*- mode: c; c-file-style: "stroustrup"; tab-width: 8; -*-
\r
96 set -eu; trg=3D`basename "$0" .c`; rm -f "$trg"
\r
97 WARN=3D"-Wall -Wno-long-long -Wstrict-prototypes -pedantic"
\r
98 WARN=3D"$WARN -Wcast-align -Wpointer-arith " # -Wfloat-equal #-Werror
\r
99 WARN=3D"$WARN -W -Wwrite-strings -Wcast-qual -Wshadow" # -Wconversion
\r
100 case ${1-} in '') set x -O2; shift; esac
\r
101 #case ${1-} in '') set x -ggdb; shift; esac
\r
102 set -x; exec ${CC:-gcc} -std=3Dc99 $WARN "$@" -o "$trg" "$0"
\r
109 * Author: Tomi Ollila -- too =C3=A4t iki piste fi
\r
111 * Created: Mon 05 Nov 2012 07:54:35 EET too
\r
112 * Last modified: Mon 05 Nov 2012 08:27:52 EET too
\r
117 #define _POSIX_SOURCE
\r
121 time_t xtimegm(struct tm * atm)
\r
124 time_t t =3D mktime(atm);
\r
128 (void)gmtime_r(&t, <m);
\r
130 sd =3D (atm->tm_hour - ltm.tm_hour) * 3600 + (atm->tm_min - ltm.tm_min)=
\r
132 + (atm->tm_sec - ltm.tm_sec);
\r
134 dd =3D (atm->tm_mday - ltm.tm_mday);
\r
138 else if (dd =3D=3D -1) sd -=3D 86400; /* e.g. 3, 2 */
\r
139 else if (dd =3D=3D 1) sd +=3D 86400; /* e.g. 2, 3 */
\r
140 else if (dd > 1) sd -=3D 86400; /* e.g. 1, 31 */
\r
141 else /* dd < 1 */ sd +=3D 86400; /* e.g. 31, 1 */
\r
143 printf("sd: %d\n", sd); // test line.
\r
149 void test(int hour, int mday)
\r
157 mtm.tm_hour =3D hour;
\r
159 mtm.tm_mday =3D mday;
\r
161 mtm.tm_year =3D 100;
\r
162 mtm.tm_isdst =3D -1;
\r
164 t =3D xtimegm(&mtm);
\r
165 otm =3D gmtime(&t);
\r
167 printf("%2d %02d:%02d:%02d\n", otm->tm_mday,
\r
168 otm->tm_hour, otm->tm_min, otm->tm_sec);
\r
171 void tests(const char * tz)
\r
173 printf("TZ: %s\n", tz);
\r
174 setenv("TZ", tz, 1);
\r
188 int main(int argc, char * argv[])
\r
190 // ls /usr/share/zoneinfo...
\r