summaryrefslogtreecommitdiff
path: root/components/dfs
diff options
context:
space:
mode:
authorwinfenggao <[email protected]>2022-10-11 05:48:02 +0800
committerGitHub <[email protected]>2022-10-10 17:48:02 -0400
commit74fd07a56514bcd61d0645b1a3d34f3b06b20678 (patch)
treee0cf69e646dbcda0d6a0b1414d7c203664000599 /components/dfs
parent0eba85eed4c2a3963608ae5a7e441b6318b658bf (diff)
lseek()函数中,当seek到文件的位置和当前位置相同时,不需要调用dfs_file_lseek()函数,直接返回当前位置即可。 (#6498)
当seek到文件的位置和当前位置相同时,不需要调用dfs_file_lseek()函数,直接返回当前位置即可。 同时,以lseek(fd,0,SEEK_CUR)的方式执行函数可以返回文件当前读去位置,可以实现 ftell()的功能. 以lseek(fd,0,SEEK_CUR)的方式执行函数返回文件当前位置,实现ftell()的功能时不用调用dfs_file_lseek()函数,提高效率;seek(fd,0,SEEK_CUR)本来就能返回当前位置。
Diffstat (limited to 'components/dfs')
-rw-r--r--components/dfs/src/dfs_posix.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c
index 3008a06da5..c406dd5fdb 100644
--- a/components/dfs/src/dfs_posix.c
+++ b/components/dfs/src/dfs_posix.c
@@ -248,15 +248,17 @@ off_t lseek(int fd, off_t offset, int whence)
return -1;
}
- result = dfs_file_lseek(d, offset);
- if (result < 0)
+ if(offset != d->pos)
{
- fd_put(d);
- rt_set_errno(result);
+ result = dfs_file_lseek(d, offset);
+ if (result < 0)
+ {
+ fd_put(d);
+ rt_set_errno(result);
- return -1;
+ return -1;
+ }
}
-
/* release the ref-count of fd */
fd_put(d);