<<On Mon, 6 Jun 2022 14:41:15 -0700, Paul Eggert via tz <tz@iana.org> said:
On 6/6/22 13:25, enh wrote:
int saved_errno = errno; errno = 0; if (mktime() == -1 && errno != 0) {
That isn't portable, because mktime can set errno and then successfully return -1, which means the caller can't rely on errno to decide whether mktime succeeded. I'm pretty sure this sort of behavior can happen on popular platforms.
The general rule for POSIX (and ISO C) interfaces is that unless specified otherwise, a standard library interface may never set errno to zero. As Paul notes, only some interfaces are explicitly specified to leave errno unchanged; those that are not so specified may set it to any nonzero value on success. The current POSIX standard definition of mktime() specifies only the permissive "may set errno to indicate the error" (as an extension to the C standard) and does not require that errno be preserved on success. So portable applications cannot assume that errno will be meaningful even when mktime() does experience an error. -GAWollman