From 74fd07a56514bcd61d0645b1a3d34f3b06b20678 Mon Sep 17 00:00:00 2001 From: winfenggao <104723992+winfenggao@users.noreply.github.com> Date: Tue, 11 Oct 2022 05:48:02 +0800 Subject: lseek()函数中,当seek到文件的位置和当前位置相同时,不需要调用dfs_file_lseek()函数,直接返回当前位置即可。 (#6498) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当seek到文件的位置和当前位置相同时,不需要调用dfs_file_lseek()函数,直接返回当前位置即可。 同时,以lseek(fd,0,SEEK_CUR)的方式执行函数可以返回文件当前读去位置,可以实现 ftell()的功能. 以lseek(fd,0,SEEK_CUR)的方式执行函数返回文件当前位置,实现ftell()的功能时不用调用dfs_file_lseek()函数,提高效率;seek(fd,0,SEEK_CUR)本来就能返回当前位置。 --- components/dfs/src/dfs_posix.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'components/dfs/src') 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); -- cgit v1.3.1