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

Function seekdir

components/dfs/dfs_v2/src/dfs_posix.c:1076–1111  ·  view source on GitHub ↗

* this function is a POSIX compliant version, which will set position of * next directory structure in the directory stream. * * @param d the directory stream. * @param offset the offset in directory stream. */

Source from the content-addressed store, hash-verified

1074 * @param offset the offset in directory stream.
1075 */
1076void seekdir(DIR *d, long offset)
1077{
1078 struct dfs_file *file;
1079
1080 if (d == NULL)
1081 {
1082 rt_set_errno(-EBADF);
1083 return;
1084 }
1085
1086 file = fd_get(d->fd);
1087 if (file == NULL)
1088 {
1089 rt_set_errno(-EBADF);
1090
1091 return;
1092 }
1093
1094 if (d && d->fd > 0)
1095 {
1096 if (file->fpos > offset)
1097 {
1098 /* seek to the offset position of directory */
1099 if (dfs_file_lseek(fd_get(d->fd), 0, SEEK_SET) >= 0)
1100 d->num = d->cur = 0;
1101 }
1102
1103 while(file->fpos < offset)
1104 {
1105 if (!readdir(d))
1106 {
1107 break;
1108 }
1109 }
1110 }
1111}
1112RTM_EXPORT(seekdir);
1113
1114/**

Callers

nothing calls this directly

Calls 4

rt_set_errnoFunction · 0.85
fd_getFunction · 0.70
dfs_file_lseekFunction · 0.70
readdirFunction · 0.70

Tested by

no test coverage detected