arch/sim/src/sim/up_hostfs.c: hostfs skip '.' and '..' in readdir'

This commit is contained in:
Xiang Xiao 2019-10-07 21:43:59 -06:00 committed by Gregory Nutt
parent 3bc62f1ccc
commit 9f0502f8ba

View File

@ -292,11 +292,24 @@ int host_readdir(void* dirp, struct nuttx_dirent_s* entry)
{
struct dirent *ent;
/* Call the host's readdir routine */
ent = readdir(dirp);
if (ent != NULL)
for (; ; )
{
/* Call the host's readdir routine */
ent = readdir(dirp);
if (ent == NULL)
{
break;
}
/* Skip '.' and '..' */
if (ent->d_name[0] == '.' && (ent->d_name[1] == '\0' ||
(ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
{
continue;
}
/* Copy the entry name */
strncpy(entry->d_name, ent->d_name, sizeof(entry->d_name));