readdir_r in newlib/libc/posix/readdir_r.c returns errno if getdents fails or reaches the end of the directory (a return of 0). But getdents only sets errno on negative returns. If a previous library call had failed and set errno, it would keep this value and readdir_r returns an error instead of 0 on EOF. David Benjamin