浏览代码

Fixed issue where seeking to end-of-directory return LFS_ERR_INVAL

This was just an oversight. Seeking to the end of the directory should
not error, but instead restore the directory to the state where the next
read returns 0.

Note this matches the behavior of lfs_file_tell/lfs_file_seek.

Found by sosthene-nitrokey
Christopher Haster 2 年之前
父节点
当前提交
b33a5b3f85
共有 1 个文件被更改,包括 5 次插入5 次删除
  1. 5 5
      lfs.c

+ 5 - 5
lfs.c

@@ -2595,11 +2595,6 @@ static int lfs_dir_rawseek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) {
     dir->id = (off > 0 && lfs_pair_cmp(dir->head, lfs->root) == 0);
     dir->id = (off > 0 && lfs_pair_cmp(dir->head, lfs->root) == 0);
 
 
     while (off > 0) {
     while (off > 0) {
-        int diff = lfs_min(dir->m.count - dir->id, off);
-        dir->id += diff;
-        dir->pos += diff;
-        off -= diff;
-
         if (dir->id == dir->m.count) {
         if (dir->id == dir->m.count) {
             if (!dir->m.split) {
             if (!dir->m.split) {
                 return LFS_ERR_INVAL;
                 return LFS_ERR_INVAL;
@@ -2612,6 +2607,11 @@ static int lfs_dir_rawseek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) {
 
 
             dir->id = 0;
             dir->id = 0;
         }
         }
+
+        int diff = lfs_min(dir->m.count - dir->id, off);
+        dir->id += diff;
+        dir->pos += diff;
+        off -= diff;
     }
     }
 
 
     return 0;
     return 0;