add test for errno for readdir (and not just opendir and closedir). Thing is the others return -1 for error, readdir returns NULL, which is also return value for "work finished"