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