Browse Source

Let's be a bit more consistant with error reporting and having "NO ERROR" reported when a function do not fail.

Godzil 1 year ago
parent
commit
9189728205
1 changed files with 13 additions and 0 deletions
  1. 13 0
      miniffs.c

+ 13 - 0
miniffs.c

@@ -34,6 +34,7 @@ file_t *miniffs_open(miniffs_t *fs, const char *filename)
     }
 
     ret->offset = 0;
+    miniffs_seterror(MINIFFS_NOERROR);
     goto exit;
 
 free_and_exit:
@@ -52,11 +53,16 @@ int miniffs_close(file_t *file)
     file->fent = NULL;
 
     free(file);
+
+    miniffs_seterror(MINIFFS_NOERROR);
 }
 
 void *miniffs_map(file_t *file)
 {
     miniffs_t *fs = (miniffs_t *)file->private_data;
+
+    miniffs_seterror(MINIFFS_NOERROR);
+
     return miniffs_getfileaddr(fs, file->fent);
 }
 
@@ -73,6 +79,10 @@ uint8_t miniffs_read(file_t *file)
         miniffs_seterror(MINIFFS_END_OF_FILE);
         file->offset = file->fent->size - 1;
     }
+    else
+    {
+        miniffs_seterror(MINIFFS_NOERROR);
+    }
 
     return ret;
 }
@@ -97,6 +107,7 @@ int miniffs_read_blocks(void *ptr, size_t size, size_t nmemb, file_t *file)
         }
     }
     file->offset = fileOffset;
+    miniffs_seterror(MINIFFS_NOERROR);
     return blockCount;
 }
 
@@ -118,10 +129,12 @@ int miniffs_seek(file_t *file, size_t offset, int whence)
         file->offset = file->fent->size - offset;
         break;
     }
+    miniffs_seterror(MINIFFS_NOERROR);
 }
 
 size_t miniffs_tell(file_t *file)
 {
+    miniffs_seterror(MINIFFS_NOERROR);
     return file->offset;
 }