Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Feb 2008 09:30:04 -0700 (MST)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        kientzle@freebsd.org
Cc:        src-committers@freebsd.org, cvs-all@freebsd.org, cvs-src@freebsd.org
Subject:   Re: cvs commit: src/lib/libarchive archive_read_support_format_iso9660.c
Message-ID:  <20080219.093004.-1749705352.imp@bsdimp.com>
In-Reply-To: <47BA963B.2060704@freebsd.org>
References:  <200802190602.m1J622Fe079227@repoman.freebsd.org> <20080219071953.GP64299@server.vk2pj.dyndns.org> <47BA963B.2060704@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
In message: <47BA963B.2060704@freebsd.org>
            Tim Kientzle <kientzle@FreeBSD.org> writes:
: Peter Jeremy wrote:
: > On Tue, Feb 19, 2008 at 06:02:02AM +0000, Tim Kientzle wrote:
: > 
: >> Without that, I
: >> don't see a really good alternative to just giving up and converting to
: >> localtime with mktime().
: > 
: > mktime() and timegm() basically use successive approximation (binary
: > search) with localtime() and gmtime() - so you can fairly easily
: > create your own timegm().
: 
: I'll probably do this soon.  I thought I had some useful
: workarounds, but each one has broken down on some system
: or another.
: 
: > If you have a normalised date, I have a direct formula to go from
: > year/month/day to number of days past some epoch ...
: 
: I have such code as well, but it has some assumptions
: that I'm wary of:
: * ISO C doesn't require that time_t count seconds
:    (POSIX does, so this is probably not a real concern
:    in practice)

time_t is defined in 7.23.3.5.2 to be:
       [#2] The time function determines the current calendar time.
       The encoding of the value is unspecified.

so time_t can be anything, really, and still conform to the ANSI-C
standard.  It must also be an arithmetic type.  But it could return
the number of days since Julius Caesar assumed the thrown so long as
difftime() returns the number of seconds.  POSIX is more demanding
here and, despite its many flaws, is better.

: * None of the standards defines the epoch (if I remember
:    correctly, old Mac OS used a different epoch, so this is
:    not entirely academic).

POSIX defines the epoch to be Jan 1, 1970, which effectively defines
it for everybody.

: I've also considered trying to measure the local system
: epoch and then use direct calculation from there, but
: that's also really messy to get right.  The binary
: search seems the most robust approach; I just haven't
: had time to research it yet.

localtime suffers from too many discontinuities to be 'easy' to
compute.

Warner



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080219.093004.-1749705352.imp>