<div dir="ltr">Thanks Jamie, I agree with everything you said. The code would be better modified as you indicate. <br><br><div class="gmail_quote">On Sat, Sep 20, 2008 at 11:58 AM, Jamie Lokier <span dir="ltr"><<a href="mailto:jamie@shareable.org">jamie@shareable.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">Farrell Aultman wrote:<br>
> The code assumed that when strol is successful, that it will set<br>
> errno to zero. This is not the case, at least under uClinux.<br>
<br>
</div>It's not the case in general, POSIX doesn't require it to be set to zero.<br>
<div class="Ih2E3d"><br>
> The man page does not indicate this either. What can happen is that<br>
> errno is already set to non-zero before strol is called, then strol<br>
> is successful but since strol doesn't reset errno to zero, the next<br>
> line thinks that strol failed.<br>
<br>
</div>That's right. The correct way to call strtol in general, if you're<br>
checking errno after, is to set errno to zero before.<br>
<br>
Since reading errno can be slow (in threaded programs), you might want<br>
to check if the result from strtol is LONG_MIN or LONG_MAX before<br>
checking errno.<br>
<font color="#888888"><br>
-- Jamie<br>
</font></blockquote></div><br></div>