Browse Source

Add a primitive write function and function to get the version.

MiniFFS is not really meant to write in the files, but in some cases it could be needed so that was added for that reason. If the changes are applied or not to the actual file is implementation dependent. So be careful.
Godzil 1 year ago
parent
commit
63a1cb6c11
2 changed files with 31 additions and 0 deletions
  1. 3 0
      includes/miniffs.h
  2. 28 0
      miniffs.c

+ 3 - 0
includes/miniffs.h

@@ -94,6 +94,9 @@ uint8_t miniffs_read(file_t *file);                                          /**
 int miniffs_seek(file_t *file, size_t offset, int whence);                   /***< Set position in a file */
 size_t miniffs_tell(file_t *file);                                           /***< Get current position in a file*/
 
+int miniffs_write(file_t *file, char value);
+char *miniffs_getversion();
+
 typedef enum miniffs_error_t
 {
     MINIFFS_NOERROR = 0,

+ 28 - 0
miniffs.c

@@ -90,6 +90,29 @@ uint8_t miniffs_read(file_t *file)
     return ret;
 }
 
+int miniffs_write(file_t *file, char value)
+{
+    miniffs_t *fs = (miniffs_t *) file->private_data;
+    uint8_t *filePtr = miniffs_getfileaddr(fs, file->fent);
+
+
+    filePtr[file->offset] = value;
+
+    file->offset++;
+
+    if (file->offset >= file->fent->size)
+    {
+        miniffs_seterror(MINIFFS_END_OF_FILE);
+        file->offset = file->fent->size - 1;
+    }
+    else
+    {
+        miniffs_seterror(MINIFFS_NOERROR);
+    }
+
+    return 0;
+}
+
 int miniffs_read_blocks(void *ptr, size_t size, size_t nmemb, file_t *file)
 {
     int i;
@@ -220,4 +243,9 @@ exit:
 void miniffs_seterror(miniffs_error_t err)
 {
     last_error = err;
+}
+
+char *miniffs_getversion()
+{
+    return VERSION;
 }