[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EPOCHREALTIME does not behave correctly before 1970

From: Chet Ramey
Subject: Re: EPOCHREALTIME does not behave correctly before 1970
Date: Sun, 22 Aug 2021 20:24:38 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

On 8/22/21 7:52 PM, Kerin Millar wrote:
On Sun, 22 Aug 2021 16:13:28 -0400
Chet Ramey <chet.ramey@case.edu> wrote:

On 8/21/21 1:28 AM, Emanuele Torre wrote:

Bash Version: 5.1
Patch Level: 8
Release Status: release

get_epochrealtime() casts tv.tv_sec (a time_t a.k.a. int) to unsigned
int causing EPOCHREALTIME to not behave correctly before the Unix Epoch.

The definition is seconds since the Unix epoch. It's not surprising that it
doesn't pay attention to dates before that.

The problem with this statement is that EPOCHREALTIME is permitted to get it 
wrong, yet EPOCHSECONDS is permitted to get it right. The discrepancy certainly 
came as a surprise to me.

It's whatever the kernel tells you is ok. EPOCHSECONDS uses time();
EPOCHREALTIME uses gettimeofday(). Both are defined to return the time
in seonds (and, in the latter case, microseconds) since the epoch. You can
argue that bash should check whether the return value of seconds is < 0,
but that isn't one of the defined failure modes.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]