Browse Source

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)本来就能返回当前位置。
winfenggao 2 years ago
parent
commit
74fd07a565
1 changed files with 8 additions and 6 deletions
  1. 8 6
      components/dfs/src/dfs_posix.c

+ 8 - 6
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);