<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 6, 2022 at 2:53 PM Garrett Wollman via tz <<a href="mailto:tz@iana.org">tz@iana.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><<On Mon, 6 Jun 2022 14:41:15 -0700, Paul Eggert via tz <<a href="mailto:tz@iana.org" target="_blank">tz@iana.org</a>> said:<br>
<br>
> On 6/6/22 13:25, enh wrote:<br>
>> int saved_errno = errno;<br>
>> errno = 0;<br>
>> if (mktime() == -1 && errno != 0) {<br>
<br>
> That isn't portable, because mktime can set errno and then successfully <br>
> return -1, which means the caller can't rely on errno to decide whether <br>
> mktime succeeded. I'm pretty sure this sort of behavior can happen on <br>
> popular platforms.<br>
<br>
The general rule for POSIX (and ISO C) interfaces is that unless<br>
specified otherwise, a standard library interface may never set errno<br>
to zero.  As Paul notes, only some interfaces are explicitly specified<br>
to leave errno unchanged; those that are not so specified may set it<br>
to any nonzero value on success.  The current POSIX standard<br>
definition of mktime() specifies only the permissive "may set errno to<br>
indicate the error" (as an extension to the C standard) and does not<br>
require that errno be preserved on success.  So portable applications<br>
cannot assume that errno will be meaningful even when mktime() does<br>
experience an error.<br></blockquote><div><br></div><div>that's what it used to say (because, as eggert said, ISO C only has that weak guarantee), but the *current* POSIX text is stronger:</div><div><br></div><div>The mktime() function shall return the specified time since the Epoch encoded as a value of type time_t. If the time since the Epoch cannot be represented, the function shall return the value (time_t)-1 [CX] [Option Start]  and set errno to indicate the error. [Option End]<br></div><div><br></div><div><a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/mktime.html">https://pubs.opengroup.org/onlinepubs/9699919799/functions/mktime.html</a><br></div><div><br></div><div>(the "CX" option is how POSIX says "we deviate from ISO C here".)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-GAWollman<br>
</blockquote></div></div>