MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / readdir

Function readdir

components/dfs/dfs_v1/src/dfs_posix.c:760–797  ·  view source on GitHub ↗

* this function is a POSIX compliant version, which will return a pointer * to a dirent structure representing the next directory entry in the * directory stream. * * @param d the directory stream pointer. * * @return the next directory entry, NULL on the end of directory or failed. */

Source from the content-addressed store, hash-verified

758 * @return the next directory entry, NULL on the end of directory or failed.
759 */
760struct dirent *readdir(DIR *d)
761{
762 int result;
763 struct dfs_file *fd;
764
765 fd = fd_get(d->fd);
766 if (fd == NULL)
767 {
768 rt_set_errno(-EBADF);
769 return NULL;
770 }
771
772 if (d->num)
773 {
774 struct dirent *dirent_ptr;
775 dirent_ptr = (struct dirent *)&d->buf[d->cur];
776 d->cur += dirent_ptr->d_reclen;
777 }
778
779 if (!d->num || d->cur >= d->num)
780 {
781 /* get a new entry */
782 result = dfs_file_getdents(fd,
783 (struct dirent *)d->buf,
784 sizeof(d->buf) - 1);
785 if (result <= 0)
786 {
787 rt_set_errno(result);
788
789 return NULL;
790 }
791
792 d->num = result;
793 d->cur = 0; /* current entry index */
794 }
795
796 return (struct dirent *)(d->buf + d->cur);
797}
798RTM_EXPORT(readdir);
799
800/**

Callers 7

directory_delete_for_mshFunction · 0.50
directory_setattrFunction · 0.50
msh_auto_complete_pathFunction · 0.50
libc_direntFunction · 0.50
list_dirFunction · 0.50
seekdir_testFunction · 0.50

Calls 3

rt_set_errnoFunction · 0.85
fd_getFunction · 0.70
dfs_file_getdentsFunction · 0.70

Tested by 1