[tz] Invalid tm handling in %s pattern in strftime

Garrett Wollman wollman at csail.mit.edu
Mon Jun 6 21:52:35 UTC 2022

<<On Mon, 6 Jun 2022 14:41:15 -0700, Paul Eggert via tz <tz at 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.


More information about the tz mailing list