diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 96139837e98..a7d6159a1ce 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -537,12 +537,17 @@ struct dirent *readdir(DIR *d) if (fd == RT_NULL) { rt_set_errno(-DFS_STATUS_EBADF); - return RT_NULL; } - if (!d->num || - (d->cur += ((struct dirent *)(d->buf + d->cur))->d_reclen) >= d->num) + if (d->num) + { + struct dirent* dirent_ptr; + dirent_ptr = (struct dirent*)&d->buf[d->cur]; + d->cur += dirent_ptr->d_reclen; + } + + if (!d->num || d->cur >= d->num) { /* get a new entry */ result = dfs_file_getdents(fd, diff --git a/components/libc/newlib/syscalls.c b/components/libc/newlib/syscalls.c index 5b829f47532..388d240c944 100644 --- a/components/libc/newlib/syscalls.c +++ b/components/libc/newlib/syscalls.c @@ -3,6 +3,14 @@ #include #include +#ifdef RT_USING_DFS +#include +#endif + +#ifdef RT_USING_PTHREADS +#include +#endif + /* Reentrant versions of system calls. */ int