[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gettime's gettimeofday call may fail
From: |
Jim Meyering |
Subject: |
gettime's gettimeofday call may fail |
Date: |
Sun, 23 Oct 2005 00:34:09 +0200 |
FYI,
I've just realized that gnulib's gettime function (currently
returning void) can fail, albeit under unusual circumstances.
On at least Solaris 9, gettimeofday is documented to fail like this:
Additionally, the gettimeofday() function will fail for 32-bit
interfaces if:
EOVERFLOW
The system time has progressed beyond 2038, thus the
size of the tv_sec member of the timeval structure
pointed to by tp is insufficient to hold the current
time in seconds.
And something similar must happen on any system that has a
wider-than-32-bit clock counting seconds since the epoch, and that
also provides an environment where at least time_t is narrower.
Presuming that the same problem afflicts clock_gettime(3rt) or
that clock_gettime is not available for 32-bit time_t, then
gettime may return with *TS uninitialized.
At first I thought this meant we'd have to change gettime to
return an indication of success or failure. However, I am now
inclined to leave it as is. Anyone who sets the system clock past
2038 and then runs a gnulib-based program that they've compiled in
hamstrung-to-32-bit-time_t mode deserves whatever misbehavior they
provoke.
I figure that long before 2038 rolls around for real, everyone will
be using time_t that is sufficiently wide, so this won't be a problem.
- gettime's gettimeofday call may fail,
Jim Meyering <=