diff --git a/lib/posix/fs.c b/lib/posix/fs.c index 0b479039b55..04e4b872019 100644 --- a/lib/posix/fs.c +++ b/lib/posix/fs.c @@ -290,6 +290,11 @@ struct dirent *readdir(DIR *dirp) return NULL; } + if (fdirent.name[0] == 0) { + /* assume end-of-dir, leave errno untouched */ + return NULL; + } + rc = strlen(fdirent.name); rc = (rc < MAX_FILE_NAME) ? rc : (MAX_FILE_NAME - 1); (void)memcpy(pdirent.d_name, fdirent.name, rc);