Replace readdir() by thread-safe readdir_r() function