On Wed, Apr 22, 2015 at 01:50:31AM +0200, Matthias Andree wrote:

> I would like to chime in here.  I believe there is a misunderstanding of
> the API, IEEE Std 1003.1, 2013 Edition aka. The Open Group Base
> Specifications Issue 7 for readdir() explicitly state that on
> end-of-directory, errno is not changed, and applications that need to
> check for errors, should zero it beforehand.

I also did not expect readdir() to preemptively clear errno.

The real issue is that NULL returns from readdir(), and many other
functions don't distinguish between normal end of data or no matching
data, and error conditions that lead to the same.  These are API
limitations, and the work-around (where the function actually sets
errno on error) is to clear errno, and test it after.

A similar strategy is needed with strtol() for ERANGE, ...

> There is also normative prose on errno, or errno.h, that no function in
> the respective volume of said standard shall reset errno to 0.

As expected.

-- 
        Viktor.

Reply via email to