<div dir="ltr">Thanks Jamie, I agree with everything you said.&nbsp; 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">&lt;<a href="mailto:jamie@shareable.org">jamie@shareable.org</a>&gt;</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>
&gt; The code assumed that when strol is successful, that it will set<br>
&gt; errno to zero. &nbsp;This is not the case, at least under uClinux.<br>
<br>
</div>It&#39;s not the case in general, POSIX doesn&#39;t require it to be set to zero.<br>
<div class="Ih2E3d"><br>
&gt; The man page does not indicate this either. &nbsp;What can happen is that<br>
&gt; errno is already set to non-zero before strol is called, then strol<br>
&gt; is successful but since strol doesn&#39;t reset errno to zero, the next<br>
&gt; line thinks that strol failed.<br>
<br>
</div>That&#39;s right. &nbsp;The correct way to call strtol in general, if you&#39;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>