mirror of
https://gitlab.com/80486DX2-66/gists
synced 2025-05-31 08:31:41 +05:30
reverse-ramdisk.c: implement tf_finish
This commit is contained in:
@@ -14,8 +14,6 @@
|
|||||||
* and/or with set macro DEBUG (using -DDEBUG) to enable debug mode
|
* and/or with set macro DEBUG (using -DDEBUG) to enable debug mode
|
||||||
*
|
*
|
||||||
* TODO:XXX: `tf_free`: Do not shift the array, only empty entry
|
* TODO:XXX: `tf_free`: Do not shift the array, only empty entry
|
||||||
* TODO:XXX: Implement function `tf_finish` to free the array of TempFiles
|
|
||||||
* structs
|
|
||||||
* TODO:XXX: `tf_free`, `tf_write`, `tf_read`: Do not use `ID` as `index`, but
|
* TODO:XXX: `tf_free`, `tf_write`, `tf_read`: Do not use `ID` as `index`, but
|
||||||
* look for it in TempFile structs
|
* look for it in TempFile structs
|
||||||
* TODO:XXX: Set freed memory pointers to NULL
|
* TODO:XXX: Set freed memory pointers to NULL
|
||||||
@@ -82,6 +80,7 @@ int tf_alloc(size_t n, size_t type_size);
|
|||||||
int tf_free(int ID);
|
int tf_free(int ID);
|
||||||
int tf_write(int ID, size_t offset, void* src, size_t data_size);
|
int tf_write(int ID, size_t offset, void* src, size_t data_size);
|
||||||
int tf_read(int ID, size_t offset, void* dest, size_t data_size);
|
int tf_read(int ID, size_t offset, void* dest, size_t data_size);
|
||||||
|
void tf_finish(void);
|
||||||
|
|
||||||
int tf_alloc(size_t n, size_t type_size) {
|
int tf_alloc(size_t n, size_t type_size) {
|
||||||
DBG_PRINT("tf_alloc(%zu, %zu)\n", n, type_size);
|
DBG_PRINT("tf_alloc(%zu, %zu)\n", n, type_size);
|
||||||
@@ -375,6 +374,17 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tf_finish(void) {
|
||||||
|
DBG_PRINT("tf_finish()\n");
|
||||||
|
|
||||||
|
for (size_t i = 0; i < num_temp_files; i++)
|
||||||
|
if (temp_files[i].file_path != NULL)
|
||||||
|
tf_free(temp_files[i].ID);
|
||||||
|
free(temp_files);
|
||||||
|
temp_files = NULL;
|
||||||
|
num_temp_files = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
int main(void) {
|
int main(void) {
|
||||||
DBG_PRINT("started\n");
|
DBG_PRINT("started\n");
|
||||||
@@ -440,6 +450,8 @@ int main(void) {
|
|||||||
tf_free(ID_2);
|
tf_free(ID_2);
|
||||||
DBG_PRINT("freed both files\n");
|
DBG_PRINT("freed both files\n");
|
||||||
|
|
||||||
|
tf_finish();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user