CringeDB/System Abstraction/cdb_system.h
2024-02-18 17:42:05 +01:00

46 lines
2.2 KiB
C

//TODO finland up
//#include <stddef.h>
// 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 <stddef.h>
//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);