Dag-Erling Smrgrav via tz said:
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.
That doesn't prove things, because it could be set before an error was determined. Library functions and system calls never set errno to 0. So the usual answer is to set errno to 0 before the call and see if it's still 0 afterwards. If so, there was no error. If not, there might have been an error. I don't think there's any way to determine if return -1 and errno changed indicates an error or not. -- Clive D.W. Feather | If you lie to the compiler, Email: clive@davros.org | it will get its revenge. Web: http://www.davros.org | - Henry Spencer Mobile: +44 7973 377646