--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 322CE431FB6\r
+ for <notmuch@notmuchmail.org>; Mon, 5 Nov 2012 04:09:35 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id B6OED79nH9wW for <notmuch@notmuchmail.org>;\r
+ Mon, 5 Nov 2012 04:09:34 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 0B550431FAE\r
+ for <notmuch@notmuchmail.org>; Mon, 5 Nov 2012 04:09:34 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 98973100094;\r
+ Mon, 5 Nov 2012 14:09:33 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Blake Jones <blakej@foo.net>, Jani Nikula <jani@nikula.org>\r
+Subject: Re: [PATCH 10/10] timegm: add portable implementation (Solaris\r
+ support)\r
+In-Reply-To: <12349.1352043650@foo.net>\r
+References: <12349.1352043650@foo.net>\r
+User-Agent: Notmuch/0.14+81~gb8371cd (http://notmuchmail.org) Emacs/24.2.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Mon, 05 Nov 2012 14:09:33 +0200\r
+Message-ID: <m2txt4jloi.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/mixed; boundary="=-=-="\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 05 Nov 2012 12:09:35 -0000\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+\r
+On Sun, Nov 04 2012, Blake Jones wrote:\r
+\r
+> Hi Jani,\r
+>\r
+>> I'd prefer to use timegm() where available, and the suggested\r
+>> alternative [1] elsewhere.\r
+>> \r
+>> [1] http://www.kernel.org/doc/man-pages/online/pages/man3/timegm.3.html\r
+>\r
+> I considered this alternative, but decided against it because it's\r
+> completely MT-unsafe. I don't know whether libnotmuch itself is\r
+> MT-safe, but a process which called this routine in one thread would\r
+> temporarily throw off any timezone-related work that any other threads\r
+> were doing, even if they weren't using libnotmuch.\r
+\r
+Yet another idea for an alternative. Compile by entering 'sh xtimegm.c'\r
+and then run ./xtimegm\r
+\r
+Simple cases seems to work. Dst change may (or then may not) give one\r
+hour difference to the expected. The test "coverage" could be easily\r
+expanded to that ;)\r
+\r
+Hmm, I also found this:\r
+http://lists.gnu.org/archive/html/bug-gnulib/2003-09/msg00004.html\r
+which does 2 mktime's and one gmtime_r (without allocating tg!)...\r
+Pick any of these 3 -- or something different (e.g. less NIH if there is)\r
+\r
+> Blake\r
+\r
+\r
+Tomi\r
+\r
+\r
+--=-=-=\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: inline; filename=xtimegm.c\r
+Content-Transfer-Encoding: quoted-printable\r
+Content-Description: yet another attempt for timegm() implementation\r
+\r
+#if 0 /* -*- mode: c; c-file-style: "stroustrup"; tab-width: 8; -*-\r
+ set -eu; trg=3D`basename "$0" .c`; rm -f "$trg"\r
+ WARN=3D"-Wall -Wno-long-long -Wstrict-prototypes -pedantic"\r
+ WARN=3D"$WARN -Wcast-align -Wpointer-arith " # -Wfloat-equal #-Werror\r
+ WARN=3D"$WARN -W -Wwrite-strings -Wcast-qual -Wshadow" # -Wconversion\r
+ case ${1-} in '') set x -O2; shift; esac\r
+ #case ${1-} in '') set x -ggdb; shift; esac\r
+ set -x; exec ${CC:-gcc} -std=3Dc99 $WARN "$@" -o "$trg" "$0"\r
+ exit $?\r
+ */\r
+#endif\r
+/*\r
+ * $ xtimegm.c $\r
+ *\r
+ * Author: Tomi Ollila -- too =C3=A4t iki piste fi\r
+ *\r
+ * Created: Mon 05 Nov 2012 07:54:35 EET too\r
+ * Last modified: Mon 05 Nov 2012 08:27:52 EET too\r
+ *\r
+ * Public domain.\r
+ */\r
+\r
+#define _POSIX_SOURCE\r
+\r
+#include <time.h>\r
+\r
+time_t xtimegm(struct tm * atm)\r
+{\r
+ struct tm ltm;\r
+ time_t t =3D mktime(atm);\r
+ int sd;\r
+ int dd;\r
+\r
+ (void)gmtime_r(&t, <m);\r
+\r
+ sd =3D (atm->tm_hour - ltm.tm_hour) * 3600 + (atm->tm_min - ltm.tm_min)=\r
+ * 60\r
+ + (atm->tm_sec - ltm.tm_sec);\r
+\r
+ dd =3D (atm->tm_mday - ltm.tm_mday);\r
+\r
+ if (dd =3D=3D 0)\r
+ ;\r
+ else if (dd =3D=3D -1) sd -=3D 86400; /* e.g. 3, 2 */\r
+ else if (dd =3D=3D 1) sd +=3D 86400; /* e.g. 2, 3 */\r
+ else if (dd > 1) sd -=3D 86400; /* e.g. 1, 31 */\r
+ else /* dd < 1 */ sd +=3D 86400; /* e.g. 31, 1 */\r
+\r
+ printf("sd: %d\n", sd); // test line.\r
+\r
+ return t + sd;\r
+}\r
+\r
+#include <stdio.h>\r
+void test(int hour, int mday)\r
+{\r
+ struct tm mtm;\r
+ time_t t;\r
+ struct tm * otm;\r
+\r
+ mtm.tm_sec =3D 0;\r
+ mtm.tm_min =3D 0;\r
+ mtm.tm_hour =3D hour;\r
+\r
+ mtm.tm_mday =3D mday;\r
+ mtm.tm_mon =3D 11;\r
+ mtm.tm_year =3D 100;\r
+ mtm.tm_isdst =3D -1;\r
+\r
+ t =3D xtimegm(&mtm);\r
+ otm =3D gmtime(&t);\r
+\r
+ printf("%2d %02d:%02d:%02d\n", otm->tm_mday,\r
+ otm->tm_hour, otm->tm_min, otm->tm_sec);\r
+}\r
+\r
+void tests(const char * tz)\r
+{\r
+ printf("TZ: %s\n", tz);\r
+ setenv("TZ", tz, 1);\r
+ tzset();\r
+ test(23, 30);\r
+ test(23, 31);\r
+ test(23, 1);\r
+ test(23, 2);\r
+ printf("--\n");\r
+ test(1, 30);\r
+ test(1, 31);\r
+ test(1, 1);\r
+ test(1, 2);\r
+\r
+}\r
+\r
+int main(int argc, char * argv[])\r
+{\r
+ // ls /usr/share/zoneinfo...\r
+ tests("EET");\r
+ tests("MST");\r
+ tests("HST");\r
+ tests("NZ");\r
+\r
+ return 0;\r
+}\r
+\r
+--=-=-=--\r