needs testing

This commit is contained in:
The Arrayser 2022-08-29 11:05:24 +02:00 committed by GitHub
parent 2747fdfb44
commit c87b9cb960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,79 @@
#include "cdb_file-page.h"
#include "../System Abstraction/cdb_sustem.h"
struct fp_File_impl{
sus_File file;
unsigned long pageSize;
};
//Creates a new file, opens it, and resizes it to the specified page size
fp_File fp_fileNew(char * fileName, unsigned long pageSize){ //there shouldn't be a page, longer than 4gb
sus_File currentFile = sus_fileOpenInMem(fileName, SUS_FILE_NEW);
if(currentFile == NULL){
return NULL;
}
struct fp_File_impl * returnable = sus_heapAlloc(sizeof(struct fp_File_impl));
returnable->pageSize = pageSize;
returnable->file = currentFile;
//The new File will be initialized with one memory Unit (Byte), so this code resizes it to the pageSize
if(sus_fileResize(returnable->file, pageSize - 1) == NULL){
sus_heapFree(returnable);
return NULL;
}
return returnable;
}
fp_File fp_fileTemp(char * fileName, unsigned long pageSize){
sus_File currentFile = sus_fileOpenInMem(fileName, SUS_FILE_TEMP);
if(currentFile == NULL){
return NULL;
}
struct fp_File_impl * returnable = sus_heapAlloc(sizeof(struct fp_File_impl));
returnable->pageSize = pageSize;
returnable->file = currentFile;
//The new File will be initialized with one memory Unit (Byte), so this code resizes it to the pageSize
if(sus_fileResize(returnable->file, pageSize - 1) == NULL){
sus_heapFree(returnable);
return NULL;
}
return returnable;
}
fp_File fp_fileOpen(char * fileName){
sus_File currentFile = sus_fileOpenInMem(fileName, SUS_FILE_NOTHING);
if(currentFile == NULL){
return NULL;
}
struct fp_File_impl * returnable = sus_heapAlloc(sizeof(struct fp_File_impl));
//returnable->pageSize = pageSize;
returnable->file = currentFile;
//since this function does not read the header, there is no way of knowing, what the page size is. Somebody else has to call the fp_fileInit function for this
return returnable;
}
//Since someone else has to read the header, this function sets the read page size after fp_fileOpen has been called
void fp_fileInit(fp_File file, unsigned long pageSize){
file->pageSize = pageSize;
}
//negative values indicate the removable of the latest pages; so this library doesn't need more functions
void * fp_fileAppendPages(fp_File file, long numberOfPages){
sus_fileResize(file->file, file->pageSize * numberOfPages);
}
void * fp_fileToMemroy(fp_File file){
return sus_fileFileToMemroy(file->file);
}
void fp_fileClose(fp_File file){
sus_fileClose(file->file);
sus_heapFree(file);
}

View File

@ -0,0 +1,16 @@
typedef struct fp_File_impl * fp_File;
//Creates a new file, opens it, and resizes it to the specified page size
fp_File fp_fileNew(char * fileName, unsigned long pageSize); //there shouldn't be a page, longer than 4gb
fp_File fp_fileTemp(char * fileName, unsigned long pageSize);
fp_File fp_fileOpen(char * fileName);
//Since someone else has to read the header, this function sets the read page size after fp_fileOpen has been called
void fp_fileSetPageSize(fp_File file, unsigned long pageSize);
//negative values indicate the removable of the latest pages; so this library doesn't need more functions
void * fp_fileAppendPages(fp_File file, long numberOfPages);
void * fp_fileToMemroy(fp_File file);
void fp_fileClose(fp_File file);