[tz] mktime() clarification

Dag-Erling Smørgrav des at des.no
Mon Mar 25 19:16:33 UTC 2024


Both the C standard and POSIX state that mktime() returns -1 on failure;
POSIX additionally states that it sets errno.  However, since -1 is also
a valid result (representing 23:59:59 UTC on 1969-12-31) and POSIX never
guarantees that a successful call does not modify errno, it seems to me
that the only reliable way to determine whether mktime() succeeded,
within the bounds of the aforementioned standards, is to set tm_wday or
tm_yday to an out-of-bounds value (e.g. -1) prior to calling mktime()
and check whether it has been modified on return.  As far as I can tell,
this has been the case ever since mktime() was introduced in POSIX.1 in
1988 and XPG3 and ANSI C in 1989.  Am I wrong?  Would it be a mistake to
state this outright in the appropriate manual page?

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the tz mailing list