From e98a4b220a58efe82be0857dd31c5becaac7dd47 Mon Sep 17 00:00:00 2001 From: JDobeshow Date: Sun, 18 Feb 2024 17:42:05 +0100 Subject: [PATCH] rename definitions --- File-Page Abstraction/cdb_file-page.c | 40 +++++------ File-Page Abstraction/cdb_file-page.h | 2 +- System Abstraction/cdb_sustem.h | 46 ------------ System Abstraction/cdb_system.h | 46 ++++++++++++ System Abstraction/linux/cdb_file.c | 50 ++++++------- System Abstraction/linux/cdb_memroy.c | 12 ++-- System Abstraction/linux/cdb_thread.c | 26 +++---- System Abstraction/win32/cdb_file.c | 70 +++++++++---------- System Abstraction/win32/cdb_memroy.c | 16 ++--- System Abstraction/win32/cdb_thread.c | 18 ++--- cdb_sustem.h | 45 ------------ tests/File-Page Abstraction/1/compile.sh | 2 +- tests/File-Page Abstraction/1/filePageTest1.c | 4 +- tests/File-Page Abstraction/2/compile.sh | 2 +- tests/File-Page Abstraction/2/filePageTest2.c | 2 +- tests/System Abstraction/1/compile.bat | 2 +- tests/System Abstraction/1/compile.sh | 2 +- .../1/systemAbstractionTest1.c | 36 +++++----- tests/System Abstraction/2/compile.bat | 2 +- tests/System Abstraction/2/compile.sh | 2 +- tests/System Abstraction/2/openNewFiletest.c | 38 +++++----- tests/System Abstraction/3/compile.bat | 2 +- tests/System Abstraction/3/compile.sh | 2 +- tests/System Abstraction/3/openTempFiletest.c | 30 ++++---- .../3/openTempFiletest.c_old | 38 +++++----- tests/System Abstraction/4/compile.sh | 2 +- tests/System Abstraction/4/renameFiletest.c | 2 +- tests/System Abstraction/5/compile.bat | 2 +- tests/System Abstraction/5/compile.sh | 2 +- tests/System Abstraction/5/threadsTest.c | 6 +- 30 files changed, 252 insertions(+), 297 deletions(-) delete mode 100644 System Abstraction/cdb_sustem.h create mode 100644 System Abstraction/cdb_system.h delete mode 100644 cdb_sustem.h diff --git a/File-Page Abstraction/cdb_file-page.c b/File-Page Abstraction/cdb_file-page.c index b16b6f6..d1ffbcc 100644 --- a/File-Page Abstraction/cdb_file-page.c +++ b/File-Page Abstraction/cdb_file-page.c @@ -2,24 +2,24 @@ #include "../System Abstraction/cdb_sustem.h" struct fp_File_impl{ - sus_File file; + sys_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); + sys_File currentFile = sys_fileOpenInMem(fileName, SYS_FILE_NEW); if(currentFile == NULL){ return NULL; } - fp_File returnable = sus_heapAlloc(sizeof(struct fp_File_impl)); + fp_File returnable = sys_heapAlloc(sizeof(struct fp_File_impl)); returnable->pageSize = pageSize; returnable->file = currentFile; - //The new File will be initialized with one memroy Unit (Byte), so this code resizes it to the pageSize - if(sus_fileResize(returnable->file, pageSize - 1) == NULL){ - sus_heapFree(returnable); + //The new File will be initialized with one memory Unit (Byte), so this code resizes it to the pageSize + if(sys_fileResize(returnable->file, pageSize - 1) == NULL){ + sys_heapFree(returnable); return NULL; } @@ -27,18 +27,18 @@ fp_File fp_fileNew(char * fileName, unsigned long pageSize){ //there shouldn't b } fp_File fp_fileTemp(char * fileName, unsigned long pageSize){ - sus_File currentFile = sus_fileOpenInMem(fileName, SUS_FILE_TEMP); + sys_File currentFile = sys_fileOpenInMem(fileName, SYS_FILE_TEMP); if(currentFile == NULL){ return NULL; } - fp_File returnable = sus_heapAlloc(sizeof(struct fp_File_impl)); + fp_File returnable = sys_heapAlloc(sizeof(struct fp_File_impl)); returnable->pageSize = pageSize; returnable->file = currentFile; - //The new File will be initialized with one memroy Unit (Byte), so this code resizes it to the pageSize - if(sus_fileResize(returnable->file, pageSize - 1) == NULL){ - sus_heapFree(returnable); + //The new File will be initialized with one memory Unit (Byte), so this code resizes it to the pageSize + if(sys_fileResize(returnable->file, pageSize - 1) == NULL){ + sys_heapFree(returnable); return NULL; } @@ -46,12 +46,12 @@ fp_File fp_fileTemp(char * fileName, unsigned long pageSize){ } fp_File fp_fileOpen(char * fileName){ - sus_File currentFile = sus_fileOpenInMem(fileName, SUS_FILE_NOTHING); + sys_File currentFile = sys_fileOpenInMem(fileName, SYS_FILE_NOTHING); if(currentFile == NULL){ return NULL; } - fp_File returnable = sus_heapAlloc(sizeof(struct fp_File_impl)); + fp_File returnable = sys_heapAlloc(sizeof(struct fp_File_impl)); //returnable->pageSize = pageSize; returnable->file = currentFile; @@ -67,9 +67,9 @@ void fp_fileInit(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 *newMem = sus_fileResize(file->file, file->pageSize * numberOfPages); + void *newMem = sys_fileResize(file->file, file->pageSize * numberOfPages); if(newMem == NULL) { - sus_fileClose(file->file); + sys_fileClose(file->file); file->file = NULL; file->pageSize = 0; return NULL; @@ -78,18 +78,18 @@ void * fp_fileAppendPages(fp_File file, long numberOfPages){ return newMem; } -void * fp_fileToMemroy(fp_File file){ - return sus_fileFileToMemroy(file->file); +void * fp_fileToMemory(fp_File file){ + return sys_fileFileToMemory(file->file); } void fp_fileFlush(fp_File file) { - sus_fileFlush(file->file); + sys_fileFlush(file->file); } void fp_fileClose(fp_File file){ if(file->file != NULL) { - sus_fileClose(file->file); + sys_fileClose(file->file); } - sus_heapFree(file); + sys_heapFree(file); } \ No newline at end of file diff --git a/File-Page Abstraction/cdb_file-page.h b/File-Page Abstraction/cdb_file-page.h index 8afc7aa..da83e11 100644 --- a/File-Page Abstraction/cdb_file-page.h +++ b/File-Page Abstraction/cdb_file-page.h @@ -12,7 +12,7 @@ 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_fileToMemory(fp_File file); void fp_fileFlush(fp_File file); diff --git a/System Abstraction/cdb_sustem.h b/System Abstraction/cdb_sustem.h deleted file mode 100644 index ca4c7eb..0000000 --- a/System Abstraction/cdb_sustem.h +++ /dev/null @@ -1,46 +0,0 @@ -//TODO finland up - -//#include - -// TODO should propably be placed in a global header -#define sus_Bool char -#define sus_True 1 -#define sus_False 0 - -#define SUS_FILE_TEMP ((1UL << 0) | SUS_FILE_NEW) //A temporary file gets automatically deleted, once it is no longer needed; a temp file also has to be a new file -#define SUS_FILE_NEW (1UL << 1) -#define SUS_FILE_NOTHING 0UL - -//Naming: firstly the package, then the topic, lastly the operation - -#include - -//Operating System independent implementation -typedef struct sus_File_impl * sus_File; - -// File IO API -//sus_File sus_file_OpenInMem(char * fileName, unsigned long parameter); -sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter); // Map a file into the memroy of the current process -//void * sus_fileOpenNewinMem(char * fileName); //prevent user errors -//void * sus_fileOpenTempFileinMem(char * fileName); - -void * sus_fileFileToMemroy(sus_File file); //retrieves the memroy Pointer of where the file was mapped in memroy - -sus_Bool sus_fileExists(char * fileName); //check if a file exists in the specified path with the specified name -void sus_fileClose(sus_File file); //Closes the file mapping and all the system specific stuff for that mapping -void sus_fileFlush(sus_File file); //Flushes the filemapping; synchronize the written data in the filemapping to the actual file on disk (without blocking for better performance) -void * sus_fileResize(sus_File file, signed long appendBytes); //if appendBytes is negative, the file shrinks. This prevents me from definining a new function for retreving the file Size -void sus_fileDelete(char * fileName); -void sus_fileRename(char * fileName, char * newFileName); - -// Memory API -void * sus_heapAlloc(size_t bytes); // returns NULL, if there is no memroy left or an error occured -void * sus_heapResize(void * memroy, size_t newBytes); // returns NULL, if there is no memroy left or an error occured -void sus_heapFree(void * memroy); // what should this function do, if an error occurse.. - -// Networking API -- coming soon, cuz idk - -//Threads -typedef __attribute__ ((sysv_abi)) void (*sus_threadProc)(void * arg); -sus_Bool sus_threadNew(sus_threadProc proc, void * arg); -void sus_threadSleep(unsigned long seconds); \ No newline at end of file diff --git a/System Abstraction/cdb_system.h b/System Abstraction/cdb_system.h new file mode 100644 index 0000000..3cd057e --- /dev/null +++ b/System Abstraction/cdb_system.h @@ -0,0 +1,46 @@ +//TODO finland up + +//#include + +// TODO should propably be placed in a global header +#define sys_Bool char +#define sys_True 1 +#define sys_False 0 + +#define SYS_FILE_TEMP ((1UL << 0) | SYS_FILE_NEW) //A temporary file gets automatically deleted, once it is no longer needed; a temp file also has to be a new file +#define SYS_FILE_NEW (1UL << 1) +#define SYS_FILE_NOTHING 0UL + +//Naming: firstly the package, then the topic, lastly the operation + +#include + +//Operating System independent implementation +typedef struct sys_File_impl * sys_File; + +// File IO API +//sys_File sys_file_OpenInMem(char * fileName, unsigned long parameter); +sys_File sys_fileOpenInMem(char * fileName, unsigned long parameter); // Map a file into the memory of the current process +//void * sys_fileOpenNewinMem(char * fileName); //prevent user errors +//void * sys_fileOpenTempFileinMem(char * fileName); + +void * sys_fileFileToMemory(sys_File file); //retrieves the memory Pointer of where the file was mapped in memory + +sys_Bool sys_fileExists(char * fileName); //check if a file exists in the specified path with the specified name +void sys_fileClose(sys_File file); //Closes the file mapping and all the system specific stuff for that mapping +void sys_fileFlush(sys_File file); //Flushes the filemapping; synchronize the written data in the filemapping to the actual file on disk (without blocking for better performance) +void * sys_fileResize(sys_File file, signed long appendBytes); //if appendBytes is negative, the file shrinks. This prevents me from definining a new function for retreving the file Size +void sys_fileDelete(char * fileName); +void sys_fileRename(char * fileName, char * newFileName); + +// Memory API +void * sys_heapAlloc(size_t bytes); // returns NULL, if there is no memory left or an error occured +void * sys_heapResize(void * memory, size_t newBytes); // returns NULL, if there is no memory left or an error occured +void sys_heapFree(void * memory); // what should this function do, if an error occurse.. + +// Networking API -- coming soon, cuz idk + +//Threads +typedef __attribute__ ((sysv_abi)) void (*sys_threadProc)(void * arg); +sys_Bool sys_threadNew(sys_threadProc proc, void * arg); +void sys_threadSleep(unsigned long seconds); \ No newline at end of file diff --git a/System Abstraction/linux/cdb_file.c b/System Abstraction/linux/cdb_file.c index e7e04bb..cfbdb9d 100644 --- a/System Abstraction/linux/cdb_file.c +++ b/System Abstraction/linux/cdb_file.c @@ -1,4 +1,4 @@ -#include "../cdb_sustem.h" +#include "../cdb_system.h" #define _GNU_SOURCE #include #include @@ -8,15 +8,15 @@ #include #include -struct sus_File_impl{ - void * memroy; +struct sys_File_impl{ + void * memory; size_t length; int fd; }; -sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter) { +sys_File sys_fileOpenInMem(char * fileName, unsigned long parameter) { int flags = O_RDWR; - if(parameter & SUS_FILE_NEW) flags |= O_CREAT | O_EXCL; + if(parameter & SYS_FILE_NEW) flags |= O_CREAT | O_EXCL; int fd = open(fileName, flags, S_IRWXU); if(fd == -1) return NULL; @@ -31,7 +31,7 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter) { return NULL; } - if((parameter & SUS_FILE_TEMP) == SUS_FILE_TEMP) unlink(fileName); + if((parameter & SYS_FILE_TEMP) == SYS_FILE_TEMP) unlink(fileName); if(info.st_size == 0) { write(fd, "", 1); @@ -45,61 +45,61 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter) { return NULL; } - sus_File file = (sus_File) sus_heapAlloc(sizeof(struct sus_File_impl)); - file->memroy = mem; + sys_File file = (sys_File) sys_heapAlloc(sizeof(struct sys_File_impl)); + file->memory = mem; file->length = info.st_size; file->fd = fd; return file; } -void * sus_fileFileToMemroy(sus_File file) { - return file->memroy; +void * sys_fileFileToMemory(sys_File file) { + return file->memory; } -sus_Bool sus_fileExists(char * fileName) { +sys_Bool sys_fileExists(char * fileName) { struct stat bro; return !stat(fileName, &bro); } -void sus_fileClose(sus_File file) { - if(file->memroy != NULL) { - msync(file->memroy, file->length, MS_SYNC); - munmap(file->memroy, file->length); +void sys_fileClose(sys_File file) { + if(file->memory != NULL) { + msync(file->memory, file->length, MS_SYNC); + munmap(file->memory, file->length); close(file->fd); } - sus_heapFree(file); + sys_heapFree(file); } -void sus_fileFlush(sus_File file) { - msync(file->memroy, file->length, MS_SYNC); +void sys_fileFlush(sys_File file) { + msync(file->memory, file->length, MS_SYNC); } -void * sus_fileResize(sus_File file, signed long appendBytes) { +void * sys_fileResize(sys_File file, signed long appendBytes) { size_t newSize = file->length + appendBytes; lseek(file->fd, newSize - 1, SEEK_SET); write(file->fd, "", 1); - munmap(file->memroy, file->length); + munmap(file->memory, file->length); void *newMem = mmap(NULL, newSize, PROT_READ | PROT_WRITE, MAP_SHARED, file->fd, 0); if(newMem == MAP_FAILED) { - sus_fileClose(file); + sys_fileClose(file); file->fd = 0; file->length = 0; - file->memroy = NULL; + file->memory = NULL; return NULL; } file->length = newSize; - file->memroy = newMem; + file->memory = newMem; return newMem; } -void sus_fileDelete(char * fileName) { +void sys_fileDelete(char * fileName) { unlink(fileName); } -void sus_fileRename(char * fileName, char * newFileName) { +void sys_fileRename(char * fileName, char * newFileName) { link(fileName, newFileName); unlink(fileName); } \ No newline at end of file diff --git a/System Abstraction/linux/cdb_memroy.c b/System Abstraction/linux/cdb_memroy.c index 901fc7e..9457f4c 100644 --- a/System Abstraction/linux/cdb_memroy.c +++ b/System Abstraction/linux/cdb_memroy.c @@ -1,15 +1,15 @@ -#include "../cdb_sustem.h" +#include "../cdb_system.h" #include // Memory API -void * sus_heapAlloc(size_t bytes) { +void * sys_heapAlloc(size_t bytes) { return malloc(bytes); } -void * sus_heapResize(void * memroy, size_t newBytes) { - return realloc(memroy, newBytes); +void * sys_heapResize(void * memory, size_t newBytes) { + return realloc(memory, newBytes); } -void sus_heapFree(void * memroy) { - free(memroy); +void sys_heapFree(void * memory) { + free(memory); } \ No newline at end of file diff --git a/System Abstraction/linux/cdb_thread.c b/System Abstraction/linux/cdb_thread.c index aeed41f..462345f 100644 --- a/System Abstraction/linux/cdb_thread.c +++ b/System Abstraction/linux/cdb_thread.c @@ -1,38 +1,38 @@ -#include "../cdb_sustem.h" +#include "../cdb_system.h" #include #include -struct sus_thread_args { - sus_threadProc proc; +struct sys_thread_args { + sys_threadProc proc; void *arg; }; -typedef struct sus_thread_args sus_thread_args; +typedef struct sys_thread_args sys_thread_args; // Linux only uses System V AMD64 ABI calling convention (source: https://en.wikipedia.org/wiki/X86_calling_conventions) void *uwu_runThread(void *arg) { - sus_thread_args *args = (sus_thread_args *) arg; - sus_threadProc proc = args->proc; + sys_thread_args *args = (sys_thread_args *) arg; + sys_threadProc proc = args->proc; void *arg2 = args->arg; - sus_heapFree(args); + sys_heapFree(args); proc(arg2); return NULL; } -sus_Bool sus_threadNew(sus_threadProc proc, void *arg) { - sus_thread_args *args = (sus_thread_args *) sus_heapAlloc(sizeof(sus_thread_args)); +sys_Bool sys_threadNew(sys_threadProc proc, void *arg) { + sys_thread_args *args = (sys_thread_args *) sys_heapAlloc(sizeof(sys_thread_args)); args->proc = proc; args->arg = arg; pthread_t thread; if(pthread_create(&thread, NULL, uwu_runThread, args)) { - sus_heapFree(args); - return sus_False; + sys_heapFree(args); + return sys_False; }else { - return sus_True; + return sys_True; } } -void sus_threadSleep(unsigned long seconds) { +void sys_threadSleep(unsigned long seconds) { sleep(seconds); } \ No newline at end of file diff --git a/System Abstraction/win32/cdb_file.c b/System Abstraction/win32/cdb_file.c index a819281..3e0558a 100644 --- a/System Abstraction/win32/cdb_file.c +++ b/System Abstraction/win32/cdb_file.c @@ -1,8 +1,8 @@ -#include "../cdb_sustem.h" +#include "../cdb_system.h" #include -struct sus_File_impl{ - void * memroy; +struct sys_File_impl{ + void * memory; HANDLE fileHandle; HANDLE fileMapHandle; }; @@ -12,24 +12,24 @@ struct sus_File_impl{ // if(fileMap == NULL || fileMap == INVALID_HANDLE_VALUE){ // return NULL; // } -// void * memroy = MapViewOfFile(fileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); -// if(memroy == NULL){ +// void * memory = MapViewOfFile(fileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); +// if(memory == NULL){ // CloseHandle(fileMap); // } -// return memroy; +// return memory; //} -sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){ - sus_File currentFile = sus_heapAlloc(sizeof(struct sus_File_impl)); +sys_File sys_fileOpenInMem(char * fileName, unsigned long parameter){ + sys_File currentFile = sys_heapAlloc(sizeof(struct sys_File_impl)); if(currentFile == NULL) return NULL; currentFile->fileHandle = CreateFileA(fileName, GENERIC_READ | GENERIC_WRITE, //Open for reading and writing FILE_SHARE_READ, //It wouldn't be a good idea, if a different process wrote to the file at the same time NULL, - (parameter & SUS_FILE_NEW ? CREATE_NEW : OPEN_EXISTING), //Open the file only if it exists/if it DOES NOT EXIST to prevent user error + (parameter & SYS_FILE_NEW ? CREATE_NEW : OPEN_EXISTING), //Open the file only if it exists/if it DOES NOT EXIST to prevent user error FILE_FLAG_RANDOM_ACCESS | //optimize for random access to file - ((parameter & SUS_FILE_TEMP == SUS_FILE_TEMP) ? (FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE) : FILE_ATTRIBUTE_NORMAL), // just a normal file :D / automatically remove the file, if no longer needed + ((parameter & SYS_FILE_TEMP == SYS_FILE_TEMP) ? (FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE) : FILE_ATTRIBUTE_NORMAL), // just a normal file :D / automatically remove the file, if no longer needed NULL); if(currentFile->fileHandle == NULL || currentFile->fileHandle == INVALID_HANDLE_VALUE){ //debug @@ -39,7 +39,7 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){ } //void * currentAdress = internal_fileOpeninMem(currentFile); - //If the file is empty, there is nothing to map into memroy, so this code puts something into the file + //If the file is empty, there is nothing to map into memory, so this code puts something into the file if(GetFileSize(currentFile->fileHandle, NULL) == 0){ if(!WriteFile(currentFile->fileHandle, "", sizeof(""), NULL, NULL)){ goto cleanup2; @@ -51,8 +51,8 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){ //return NULL; goto cleanup2; } - currentFile->memroy = MapViewOfFile(currentFile->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); - if(currentFile->memroy == NULL){ + currentFile->memory = MapViewOfFile(currentFile->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); + if(currentFile->memory == NULL){ goto cleanup3; } return currentFile; @@ -68,7 +68,7 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){ cleanup2: CloseHandle(currentFile->fileHandle); cleanup1: - sus_heapFree(currentFile); + sys_heapFree(currentFile); return NULL; } @@ -113,40 +113,40 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){ // return currentAdress; //} -void * sus_fileFileToMemroy(sus_File file){ - return file->memroy; +void * sys_fileFileToMemory(sys_File file){ + return file->memory; } -void sus_fileClose(sus_File file){ - if(file->memroy == NULL){ - FlushViewOfFile(file->memroy, 0); - UnmapViewOfFile(file->memroy); +void sys_fileClose(sys_File file){ + if(file->memory == NULL){ + FlushViewOfFile(file->memory, 0); + UnmapViewOfFile(file->memory); CloseHandle(file->fileMapHandle); CloseHandle(file->fileHandle); } - sus_heapFree(file); + sys_heapFree(file); } -void sus_fileFlush(sus_File file){ - FlushViewOfFile(file->memroy, 0); +void sys_fileFlush(sys_File file){ + FlushViewOfFile(file->memory, 0); } -void sus_fileRename(char * fileName, char * newFileName){ +void sys_fileRename(char * fileName, char * newFileName){ MoveFile(fileName, newFileName); } -void sus_fileDelete(char * fileName){ +void sys_fileDelete(char * fileName){ DeleteFile(fileName); } -sus_Bool sus_fileExists(char * fileName){ +sys_Bool sys_fileExists(char * fileName){ DWORD fileAttributes = GetFileAttributes(fileName); - return (fileAttributes == INVALID_FILE_ATTRIBUTES ? sus_True : sus_False); + return (fileAttributes == INVALID_FILE_ATTRIBUTES ? sys_True : sys_False); } -void * sus_fileResize(sus_File file, signed long appendBytes){ - FlushViewOfFile(file->memroy, 0); - UnmapViewOfFile(file->memroy); +void * sys_fileResize(sys_File file, signed long appendBytes){ + FlushViewOfFile(file->memory, 0); + UnmapViewOfFile(file->memory); CloseHandle(file->fileMapHandle); SetFilePointer(file->fileHandle, appendBytes, NULL, FILE_END); //Very cursed Unix style... SetEndOfFile(file->fileHandle); @@ -157,11 +157,11 @@ void * sus_fileResize(sus_File file, signed long appendBytes){ //return NULL; goto cleanup2; } - file->memroy = MapViewOfFile(file->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); - if(file->memroy == NULL){ + file->memory = MapViewOfFile(file->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); + if(file->memory == NULL){ goto cleanup3; } - return file->memroy; + return file->memory; cleanup3: CloseHandle(file->fileMapHandle); @@ -169,8 +169,8 @@ void * sus_fileResize(sus_File file, signed long appendBytes){ cleanup2: CloseHandle(file->fileHandle); file->fileHandle = NULL; - //sus_heapFree(file); - file->memroy = NULL; + //sys_heapFree(file); + file->memory = NULL; return NULL; } \ No newline at end of file diff --git a/System Abstraction/win32/cdb_memroy.c b/System Abstraction/win32/cdb_memroy.c index 10747d9..873cde3 100644 --- a/System Abstraction/win32/cdb_memroy.c +++ b/System Abstraction/win32/cdb_memroy.c @@ -1,17 +1,17 @@ -#include "../cdb_sustem.h" +#include "../cdb_system.h" #include -// returns NULL, if there is no memroy left or an error occured -void * sus_heapAlloc(size_t bytes){ +// returns NULL, if there is no memory left or an error occured +void * sys_heapAlloc(size_t bytes){ return HeapAlloc(GetProcessHeap(), 0, bytes); //generic call to the windows heapAlloc function } -// returns NULL, if there is no memroy left or an error occured -void * sus_heapResize(void * memroy, size_t newBytes){ - return HeapReAlloc(GetProcessHeap(), 0, memroy, newBytes); +// returns NULL, if there is no memory left or an error occured +void * sys_heapResize(void * memory, size_t newBytes){ + return HeapReAlloc(GetProcessHeap(), 0, memory, newBytes); } // what should this function do, if an error occurse.. -void sus_heapFree(void * memroy){ - HeapFree(GetProcessHeap(), 0, memroy); +void sys_heapFree(void * memory){ + HeapFree(GetProcessHeap(), 0, memory); } diff --git a/System Abstraction/win32/cdb_thread.c b/System Abstraction/win32/cdb_thread.c index 13c4d4a..b28f435 100644 --- a/System Abstraction/win32/cdb_thread.c +++ b/System Abstraction/win32/cdb_thread.c @@ -1,31 +1,31 @@ -#include "../cdb_sustem.h" +#include "../cdb_system.h" #include struct threadInfo{ - sus_threadProc proc; + sys_threadProc proc; void * args; }; DWORD WINAPI threadProc(void * tiarg){ struct threadInfo * ti = tiarg; struct threadInfo currentTI = {.args = ti->args, .proc = ti->proc}; - sus_heapFree(ti); + sys_heapFree(ti); currentTI.proc(currentTI.args); return 0; } -sus_Bool sus_threadNew(sus_threadProc proc, void * arg){ - struct threadInfo * ti = sus_heapAlloc(sizeof(struct threadInfo)); +sys_Bool sys_threadNew(sys_threadProc proc, void * arg){ + struct threadInfo * ti = sys_heapAlloc(sizeof(struct threadInfo)); ti->proc = proc; ti->args = arg; if(CreateThread(NULL, 0, threadProc, ti, 0, NULL) == NULL){ - sus_heapFree(ti); - return sus_False; + sys_heapFree(ti); + return sys_False; }else{ - return sus_True; + return sys_True; } } -void sus_threadSleep(unsigned long seconds){ +void sys_threadSleep(unsigned long seconds){ Sleep(seconds * 1000); } \ No newline at end of file diff --git a/cdb_sustem.h b/cdb_sustem.h deleted file mode 100644 index 8b2a097..0000000 --- a/cdb_sustem.h +++ /dev/null @@ -1,45 +0,0 @@ -//TODO finland up - -//#include - -// TODO should propably be placed in a global header -#define sus_Bool char -#define sus_True 1 -#define sus_False 0 - -#define SUS_FILE_TEMP ((1UL << 0) | SUS_FILE_NEW) //A temporary file gets automatically deleted, once it is no longer needed; a temp file also has to be a new file -#define SUS_FILE_NEW (1UL << 1) -#define SUS_FILE_NOTHING 0UL - -//Naming: firstly the package, then the topic, lastly the operation - -#include - -//Operating System independent implementation -typedef struct sus_File_impl * sus_File; - -// File IO API -//sus_File sus_file_OpenInMem(char * fileName, unsigned long parameter); -sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter); // Map a file into the memroy of the current process -//void * sus_fileOpenNewinMem(char * fileName); //prevent user errors -//void * sus_fileOpenTempFileinMem(char * fileName); - -void * sus_fileFileToMemroy(sus_File file); //retrieves the memroy Pointer of where the file was mapped in memroy - -sus_Bool sus_fileExists(char * fileName); //check if a file exists in the specified path with the specified name -void sus_fileClose(sus_File file); //Closes the file mapping and all the system specific stuff for that mapping -void sus_fileFlush(sus_File file); //Flushes the filemapping; synchronize the written data in the filemapping to the actual file on disk (without blocking for better performance) -void * sus_fileResize(sus_File file, signed long appendBytes); //if appendBytes is negative, the file shrinks. This prevents me from definining a new function for retreving the file Size -void sus_fileDelete(char * fileName); -void sus_fileRename(char * fileName, char * newFileName); - -// Memory API -void * sus_heapAlloc(size_t bytes); // returns NULL, if there is no memroy left or an error occured -void * sus_heapResize(void * memroy, size_t newBytes); // returns NULL, if there is no memroy left or an error occured -void sus_heapFree(void * memroy); // what should this function do, if an error occurse.. - -// Networking API -- coming soon, cuz idk - -//Threads -sus_Bool sus_threadNew(int (*proc)(void)); -void sus_threadSleep(unsigned long seconds); \ No newline at end of file diff --git a/tests/File-Page Abstraction/1/compile.sh b/tests/File-Page Abstraction/1/compile.sh index bd92195..3d59af9 100755 --- a/tests/File-Page Abstraction/1/compile.sh +++ b/tests/File-Page Abstraction/1/compile.sh @@ -2,4 +2,4 @@ if [ ! -d run ]; then mkdir run fi -gcc -g filePageTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" "../../../File-Page Abstraction/cdb_file-page.c" -o run/filePageTest1 \ No newline at end of file +gcc -g filePageTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" "../../../File-Page Abstraction/cdb_file-page.c" -o run/filePageTest1 \ No newline at end of file diff --git a/tests/File-Page Abstraction/1/filePageTest1.c b/tests/File-Page Abstraction/1/filePageTest1.c index 0ca757b..9f4c15e 100644 --- a/tests/File-Page Abstraction/1/filePageTest1.c +++ b/tests/File-Page Abstraction/1/filePageTest1.c @@ -8,7 +8,7 @@ int main() { return 1; } - char * memory = fp_fileToMemroy(file); + char * memory = fp_fileToMemory(file); memory[0] = 'a'; memory[511] = 'b'; @@ -32,7 +32,7 @@ int main() { printf("Init\n"); fp_fileInit(file, 512); - memory = fp_fileToMemroy(file); + memory = fp_fileToMemory(file); printf("%c%c%c\n", memory[0],memory[511],memory[1023]); fp_fileClose(file); diff --git a/tests/File-Page Abstraction/2/compile.sh b/tests/File-Page Abstraction/2/compile.sh index 3255eb8..1876d7f 100755 --- a/tests/File-Page Abstraction/2/compile.sh +++ b/tests/File-Page Abstraction/2/compile.sh @@ -2,4 +2,4 @@ if [ ! -d run ]; then mkdir run fi -gcc -g filePageTest2.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" "../../../File-Page Abstraction/cdb_file-page.c" -o run/filePageTest2 \ No newline at end of file +gcc -g filePageTest2.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" "../../../File-Page Abstraction/cdb_file-page.c" -o run/filePageTest2 \ No newline at end of file diff --git a/tests/File-Page Abstraction/2/filePageTest2.c b/tests/File-Page Abstraction/2/filePageTest2.c index 77009e4..f6702f3 100644 --- a/tests/File-Page Abstraction/2/filePageTest2.c +++ b/tests/File-Page Abstraction/2/filePageTest2.c @@ -9,7 +9,7 @@ int main() { return 1; } - char * memory = fp_fileToMemroy(file); + char * memory = fp_fileToMemory(file); memory[0] = 'a'; memory[511] = 'b'; diff --git a/tests/System Abstraction/1/compile.bat b/tests/System Abstraction/1/compile.bat index ff3dce9..0c3da91 100644 --- a/tests/System Abstraction/1/compile.bat +++ b/tests/System Abstraction/1/compile.bat @@ -1 +1 @@ -gcc.exe systemAbstractionTest1.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memroy.c" -o systemAbstractionTest1.exe \ No newline at end of file +gcc.exe systemAbstractionTest1.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memory.c" -o systemAbstractionTest1.exe \ No newline at end of file diff --git a/tests/System Abstraction/1/compile.sh b/tests/System Abstraction/1/compile.sh index 7c44037..84e4f00 100755 --- a/tests/System Abstraction/1/compile.sh +++ b/tests/System Abstraction/1/compile.sh @@ -2,4 +2,4 @@ if [ ! -d run ]; then mkdir run fi -gcc systemAbstractionTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/systemAbstractionTest1 \ No newline at end of file +gcc systemAbstractionTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/systemAbstractionTest1 \ No newline at end of file diff --git a/tests/System Abstraction/1/systemAbstractionTest1.c b/tests/System Abstraction/1/systemAbstractionTest1.c index 668cd15..86d2090 100644 --- a/tests/System Abstraction/1/systemAbstractionTest1.c +++ b/tests/System Abstraction/1/systemAbstractionTest1.c @@ -1,32 +1,32 @@ -#include "../../../System Abstraction/cdb_sustem.h" +#include "../../../System Abstraction/cdb_system.h" #include "stdio.h" void main(){ - sus_File file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING); + sys_File file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING); if(file == NULL){ printf("file is null\n"); return; } - char * memroy = sus_fileFileToMemroy(file); - if(memroy == 0){ - printf("memroy was null\n"); + char * memory = sys_fileFileToMemory(file); + if(memory == 0){ + printf("memory was null\n"); return; }else{ - printf("Read chars: %c%c%c\n", memroy[0], memroy[1], memroy[2]); + printf("Read chars: %c%c%c\n", memory[0], memory[1], memory[2]); } - sus_fileResize(file, 2); - memroy = sus_fileFileToMemroy(file); - memroy[0] = 'a'; - memroy[1] = 'b'; - memroy[2] = 'c'; - memroy[3] = 'd'; - memroy[4] = 'e'; - sus_fileClose(file); + sys_fileResize(file, 2); + memory = sys_fileFileToMemory(file); + memory[0] = 'a'; + memory[1] = 'b'; + memory[2] = 'c'; + memory[3] = 'd'; + memory[4] = 'e'; + sys_fileClose(file); - file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING); - memroy = sus_fileFileToMemroy(file); - memroy[0] = 'O'; - sus_fileClose(file); + file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING); + memory = sys_fileFileToMemory(file); + memory[0] = 'O'; + sys_fileClose(file); } \ No newline at end of file diff --git a/tests/System Abstraction/2/compile.bat b/tests/System Abstraction/2/compile.bat index 996b4f0..57f5ea6 100644 --- a/tests/System Abstraction/2/compile.bat +++ b/tests/System Abstraction/2/compile.bat @@ -1 +1 @@ -gcc.exe openNewFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memroy.c" -o systemAbstractionTest1.exe \ No newline at end of file +gcc.exe openNewFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memory.c" -o systemAbstractionTest1.exe \ No newline at end of file diff --git a/tests/System Abstraction/2/compile.sh b/tests/System Abstraction/2/compile.sh index 090d4dd..b11f438 100755 --- a/tests/System Abstraction/2/compile.sh +++ b/tests/System Abstraction/2/compile.sh @@ -2,4 +2,4 @@ if [ ! -d run ]; then mkdir run fi -gcc -g openNewFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/openNewFiletest \ No newline at end of file +gcc -g openNewFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/openNewFiletest \ No newline at end of file diff --git a/tests/System Abstraction/2/openNewFiletest.c b/tests/System Abstraction/2/openNewFiletest.c index ceec6ff..d76e7bb 100644 --- a/tests/System Abstraction/2/openNewFiletest.c +++ b/tests/System Abstraction/2/openNewFiletest.c @@ -2,32 +2,32 @@ #include "stdio.h" void main(){ - sus_File file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NEW); + sys_File file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NEW); if(file == NULL){ printf("file is null\n"); return; } - char * memroy = sus_fileFileToMemroy(file); - if(memroy == 0){ - printf("memroy was null\n"); + char * memory = sys_fileFileToMemory(file); + if(memory == 0){ + printf("memory was null\n"); return; }else{ - printf("%c\n", memroy[0] == 0 ? 'Y' : 'N'); + printf("%c\n", memory[0] == 0 ? 'Y' : 'N'); } - sus_fileResize(file, 4); - memroy = sus_fileFileToMemroy(file); - memroy[0] = 'a'; - memroy[1] = 'b'; - memroy[2] = 'c'; - memroy[3] = 'd'; - memroy[4] = 'e'; - sus_fileFlush(file); - sus_fileClose(file); - file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING); - memroy = sus_fileFileToMemroy(file); - memroy[0] = 'O'; - sus_fileFlush(file); - sus_fileClose(file); + sys_fileResize(file, 4); + memory = sys_fileFileToMemory(file); + memory[0] = 'a'; + memory[1] = 'b'; + memory[2] = 'c'; + memory[3] = 'd'; + memory[4] = 'e'; + sys_fileFlush(file); + sys_fileClose(file); + file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING); + memory = sys_fileFileToMemory(file); + memory[0] = 'O'; + sys_fileFlush(file); + sys_fileClose(file); } \ No newline at end of file diff --git a/tests/System Abstraction/3/compile.bat b/tests/System Abstraction/3/compile.bat index 1f41d8a..51c6f64 100644 --- a/tests/System Abstraction/3/compile.bat +++ b/tests/System Abstraction/3/compile.bat @@ -1 +1 @@ -gcc.exe openTempFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memroy.c" -o openTempFiletest.exe \ No newline at end of file +gcc.exe openTempFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memory.c" -o openTempFiletest.exe \ No newline at end of file diff --git a/tests/System Abstraction/3/compile.sh b/tests/System Abstraction/3/compile.sh index 65bede7..ab90861 100755 --- a/tests/System Abstraction/3/compile.sh +++ b/tests/System Abstraction/3/compile.sh @@ -2,4 +2,4 @@ if [ ! -d run ]; then mkdir run fi -gcc -g openTempFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/openTempFiletest \ No newline at end of file +gcc -g openTempFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/openTempFiletest \ No newline at end of file diff --git a/tests/System Abstraction/3/openTempFiletest.c b/tests/System Abstraction/3/openTempFiletest.c index 59eff70..f2c5f12 100644 --- a/tests/System Abstraction/3/openTempFiletest.c +++ b/tests/System Abstraction/3/openTempFiletest.c @@ -2,34 +2,34 @@ #include "stdio.h" void main(){ - sus_File file = sus_fileOpenInMem("testfile.txt", SUS_FILE_TEMP); + sys_File file = sys_fileOpenInMem("testfile.txt", SYS_FILE_TEMP); if(file == NULL){ printf("file is null\n"); return; } - char * memroy = sus_fileFileToMemroy(file); - if(memroy == 0){ - printf("memroy was null\n"); + char * memory = sys_fileFileToMemory(file); + if(memory == 0){ + printf("memory was null\n"); return; }else{ - printf("%c\n", memroy[0] == 0 ? 'Y' : 'N'); + printf("%c\n", memory[0] == 0 ? 'Y' : 'N'); } - sus_fileResize(file, 4); - memroy = sus_fileFileToMemroy(file); - memroy[0] = 'a'; - memroy[1] = 'b'; - memroy[2] = 'c'; - memroy[3] = 'd'; - memroy[4] = 'e'; - sus_fileClose(file); + sys_fileResize(file, 4); + memory = sys_fileFileToMemory(file); + memory[0] = 'a'; + memory[1] = 'b'; + memory[2] = 'c'; + memory[3] = 'd'; + memory[4] = 'e'; + sys_fileClose(file); - file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING); + file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING); if(file == NULL) { printf("Second file is null\n"); }else { printf("Second file is NOT null\n"); - sus_fileClose(file); + sys_fileClose(file); } } \ No newline at end of file diff --git a/tests/System Abstraction/3/openTempFiletest.c_old b/tests/System Abstraction/3/openTempFiletest.c_old index ee5412d..f5f8de6 100644 --- a/tests/System Abstraction/3/openTempFiletest.c_old +++ b/tests/System Abstraction/3/openTempFiletest.c_old @@ -2,32 +2,32 @@ #include "stdio.h" void main(){ - sus_File file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NEW); + sys_File file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NEW); if(file == NULL){ printf("file is null"); return; } - char * memroy = sus_fileFileToMemroy(file); - if(memroy == 0){ - printf("memroy was null\n"); + char * memory = sys_fileFileToMemory(file); + if(memory == 0){ + printf("memory was null\n"); return; }else{ - printf("%c%c%c%c", memroy[0], memroy[1], memroy[2], memroy[3]); + printf("%c%c%c%c", memory[0], memory[1], memory[2], memory[3]); } - sus_fileResize(file, 2); - memroy = sus_fileFileToMemroy(file); - memroy[0] = 'a'; - memroy[1] = 'b'; - memroy[2] = 'c'; - memroy[3] = 'd'; - memroy[4] = 'e'; - sus_fileFlush(file); - sus_fileClose(file); - file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING); - memroy = sus_fileFileToMemroy(file); - memroy[0] = 'O'; - sus_fileFlush(file); - sus_fileClose(file); + sys_fileResize(file, 2); + memory = sys_fileFileToMemory(file); + memory[0] = 'a'; + memory[1] = 'b'; + memory[2] = 'c'; + memory[3] = 'd'; + memory[4] = 'e'; + sys_fileFlush(file); + sys_fileClose(file); + file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING); + memory = sys_fileFileToMemory(file); + memory[0] = 'O'; + sys_fileFlush(file); + sys_fileClose(file); } \ No newline at end of file diff --git a/tests/System Abstraction/4/compile.sh b/tests/System Abstraction/4/compile.sh index 6c64d24..d582c55 100644 --- a/tests/System Abstraction/4/compile.sh +++ b/tests/System Abstraction/4/compile.sh @@ -2,4 +2,4 @@ if [ ! -d run ]; then mkdir run fi -gcc -g renameFileTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/renameFileTest \ No newline at end of file +gcc -g renameFileTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/renameFileTest \ No newline at end of file diff --git a/tests/System Abstraction/4/renameFiletest.c b/tests/System Abstraction/4/renameFiletest.c index 6fcfe24..21ca431 100644 --- a/tests/System Abstraction/4/renameFiletest.c +++ b/tests/System Abstraction/4/renameFiletest.c @@ -2,5 +2,5 @@ #include "stdio.h" int main() { - sus_fileRename("testfile.txt", "renamedtestfile.txt"); + sys_fileRename("testfile.txt", "renamedtestfile.txt"); } \ No newline at end of file diff --git a/tests/System Abstraction/5/compile.bat b/tests/System Abstraction/5/compile.bat index 683c47a..d23b44b 100644 --- a/tests/System Abstraction/5/compile.bat +++ b/tests/System Abstraction/5/compile.bat @@ -1 +1 @@ -gcc.exe threadsTest.c "../../../System Abstraction/win32/cdb_thread.c" "../../../System Abstraction/win32/cdb_memroy.c" -o threadTests.exe \ No newline at end of file +gcc.exe threadsTest.c "../../../System Abstraction/win32/cdb_thread.c" "../../../System Abstraction/win32/cdb_memory.c" -o threadTests.exe \ No newline at end of file diff --git a/tests/System Abstraction/5/compile.sh b/tests/System Abstraction/5/compile.sh index 08de3a7..e9b847d 100755 --- a/tests/System Abstraction/5/compile.sh +++ b/tests/System Abstraction/5/compile.sh @@ -2,4 +2,4 @@ if [ ! -d run ]; then mkdir run fi -gcc -g threadsTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" "../../../System Abstraction/linux/cdb_thread.c" -o run/threadsTest \ No newline at end of file +gcc -g threadsTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" "../../../System Abstraction/linux/cdb_thread.c" -o run/threadsTest \ No newline at end of file diff --git a/tests/System Abstraction/5/threadsTest.c b/tests/System Abstraction/5/threadsTest.c index 52a1cd4..c5c7c9b 100644 --- a/tests/System Abstraction/5/threadsTest.c +++ b/tests/System Abstraction/5/threadsTest.c @@ -3,14 +3,14 @@ __attribute__ ((sysv_abi)) void testProc(void * arg){ printf("in testProc ... Going to sleep, %i\n", *(int *)arg); - sus_threadSleep(5); + sys_threadSleep(5); printf("after sleeping in testProc\n"); } int main(){ int amogus = 1234567; - printf("Thread creation succesfull? %i\n", sus_threadNew(&testProc, &amogus)); + printf("Thread creation succesfull? %i\n", sys_threadNew(&testProc, &amogus)); printf("Going to sleep in main Thread\n"); - sus_threadSleep(10); + sys_threadSleep(10); printf("After sleeping in main Thread\n"); } \ No newline at end of file