scsh's time.c (in scsh 0.5.2) has the following interface to the C
function time():
scheme_value scheme_time(int *hi_secs, int *lo_secs)
{
time_t t;
errno = 0;
t = time(NULL);
if( t == -1 && errno ) return ENTER_FIXNUM(errno);
*hi_secs = hi8(t);
*lo_secs = lo24(t);
return SCHFALSE;
}
I believe this to be wrong for several reaons:
- errno is not guaranteed to be an lvalue. In fact, several Unices
define errno to be a macro for a function call.
- The ANSI standard indicates that a -1 return value is the sole and
sufficient indicator of an error with time. There's no mention of
any setting of errno. Ditto with the Single UNIX specification.
I'm pretty sure POSIX does the same. Even my FreeBSD man page says:
A -1 return value indicates an error occurred, and in this case
an error code is stored in- to the global variable errno.
which I take to mean the same thing.
- I know that (since time_t on most Unices represents
seconds since January 1, 1970, but needs to be able to represent
points in time before that date) -1 could in fact be valid time, and
that taking it as an error indicator means excluding one point from
the time range.
- Moreover, I know that many Unices in fact do indicate an error via
errno. Still, there's no guarantee that errno will tell us of the
error.
However, potentially errno will *always* be 0 after a call to time,
even after an error, which means that this way of calling it will
never detect an error.
So, in conclusion, scsh should bite the bullet and exclude -1 from the
range of valid return values of time().
--
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla
|