rename definitions
This commit is contained in:
parent
c863bab412
commit
e98a4b220a
@ -2,24 +2,24 @@
|
|||||||
#include "../System Abstraction/cdb_sustem.h"
|
#include "../System Abstraction/cdb_sustem.h"
|
||||||
|
|
||||||
struct fp_File_impl{
|
struct fp_File_impl{
|
||||||
sus_File file;
|
sys_File file;
|
||||||
unsigned long pageSize;
|
unsigned long pageSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Creates a new file, opens it, and resizes it to the specified page size
|
//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_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){
|
if(currentFile == NULL){
|
||||||
return 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->pageSize = pageSize;
|
||||||
returnable->file = currentFile;
|
returnable->file = currentFile;
|
||||||
|
|
||||||
//The new File will be initialized with one memroy Unit (Byte), so this code resizes it to the pageSize
|
//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){
|
if(sys_fileResize(returnable->file, pageSize - 1) == NULL){
|
||||||
sus_heapFree(returnable);
|
sys_heapFree(returnable);
|
||||||
return NULL;
|
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){
|
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){
|
if(currentFile == NULL){
|
||||||
return 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->pageSize = pageSize;
|
||||||
returnable->file = currentFile;
|
returnable->file = currentFile;
|
||||||
|
|
||||||
//The new File will be initialized with one memroy Unit (Byte), so this code resizes it to the pageSize
|
//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){
|
if(sys_fileResize(returnable->file, pageSize - 1) == NULL){
|
||||||
sus_heapFree(returnable);
|
sys_heapFree(returnable);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,12 +46,12 @@ fp_File fp_fileTemp(char * fileName, unsigned long pageSize){
|
|||||||
}
|
}
|
||||||
|
|
||||||
fp_File fp_fileOpen(char * fileName){
|
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){
|
if(currentFile == NULL){
|
||||||
return 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->pageSize = pageSize;
|
||||||
returnable->file = currentFile;
|
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
|
//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_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) {
|
if(newMem == NULL) {
|
||||||
sus_fileClose(file->file);
|
sys_fileClose(file->file);
|
||||||
file->file = NULL;
|
file->file = NULL;
|
||||||
file->pageSize = 0;
|
file->pageSize = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -78,18 +78,18 @@ void * fp_fileAppendPages(fp_File file, long numberOfPages){
|
|||||||
return newMem;
|
return newMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * fp_fileToMemroy(fp_File file){
|
void * fp_fileToMemory(fp_File file){
|
||||||
return sus_fileFileToMemroy(file->file);
|
return sys_fileFileToMemory(file->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fp_fileFlush(fp_File file) {
|
void fp_fileFlush(fp_File file) {
|
||||||
sus_fileFlush(file->file);
|
sys_fileFlush(file->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fp_fileClose(fp_File file){
|
void fp_fileClose(fp_File file){
|
||||||
if(file->file != NULL) {
|
if(file->file != NULL) {
|
||||||
sus_fileClose(file->file);
|
sys_fileClose(file->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
sus_heapFree(file);
|
sys_heapFree(file);
|
||||||
}
|
}
|
@ -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
|
//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_fileAppendPages(fp_File file, long numberOfPages);
|
||||||
|
|
||||||
void * fp_fileToMemroy(fp_File file);
|
void * fp_fileToMemory(fp_File file);
|
||||||
|
|
||||||
void fp_fileFlush(fp_File file);
|
void fp_fileFlush(fp_File file);
|
||||||
|
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
//TODO finland up
|
|
||||||
|
|
||||||
//#include <stddef.h>
|
|
||||||
|
|
||||||
// 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 <stddef.h>
|
|
||||||
|
|
||||||
//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);
|
|
46
System Abstraction/cdb_system.h
Normal file
46
System Abstraction/cdb_system.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//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);
|
@ -1,4 +1,4 @@
|
|||||||
#include "../cdb_sustem.h"
|
#include "../cdb_system.h"
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -8,15 +8,15 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
struct sus_File_impl{
|
struct sys_File_impl{
|
||||||
void * memroy;
|
void * memory;
|
||||||
size_t length;
|
size_t length;
|
||||||
int fd;
|
int fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter) {
|
sys_File sys_fileOpenInMem(char * fileName, unsigned long parameter) {
|
||||||
int flags = O_RDWR;
|
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);
|
int fd = open(fileName, flags, S_IRWXU);
|
||||||
if(fd == -1) return NULL;
|
if(fd == -1) return NULL;
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter) {
|
|||||||
return NULL;
|
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) {
|
if(info.st_size == 0) {
|
||||||
write(fd, "", 1);
|
write(fd, "", 1);
|
||||||
@ -45,61 +45,61 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sus_File file = (sus_File) sus_heapAlloc(sizeof(struct sus_File_impl));
|
sys_File file = (sys_File) sys_heapAlloc(sizeof(struct sys_File_impl));
|
||||||
file->memroy = mem;
|
file->memory = mem;
|
||||||
file->length = info.st_size;
|
file->length = info.st_size;
|
||||||
file->fd = fd;
|
file->fd = fd;
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * sus_fileFileToMemroy(sus_File file) {
|
void * sys_fileFileToMemory(sys_File file) {
|
||||||
return file->memroy;
|
return file->memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
sus_Bool sus_fileExists(char * fileName) {
|
sys_Bool sys_fileExists(char * fileName) {
|
||||||
struct stat bro;
|
struct stat bro;
|
||||||
return !stat(fileName, &bro);
|
return !stat(fileName, &bro);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_fileClose(sus_File file) {
|
void sys_fileClose(sys_File file) {
|
||||||
if(file->memroy != NULL) {
|
if(file->memory != NULL) {
|
||||||
msync(file->memroy, file->length, MS_SYNC);
|
msync(file->memory, file->length, MS_SYNC);
|
||||||
munmap(file->memroy, file->length);
|
munmap(file->memory, file->length);
|
||||||
close(file->fd);
|
close(file->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
sus_heapFree(file);
|
sys_heapFree(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_fileFlush(sus_File file) {
|
void sys_fileFlush(sys_File file) {
|
||||||
msync(file->memroy, file->length, MS_SYNC);
|
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;
|
size_t newSize = file->length + appendBytes;
|
||||||
lseek(file->fd, newSize - 1, SEEK_SET);
|
lseek(file->fd, newSize - 1, SEEK_SET);
|
||||||
write(file->fd, "", 1);
|
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);
|
void *newMem = mmap(NULL, newSize, PROT_READ | PROT_WRITE, MAP_SHARED, file->fd, 0);
|
||||||
if(newMem == MAP_FAILED) {
|
if(newMem == MAP_FAILED) {
|
||||||
sus_fileClose(file);
|
sys_fileClose(file);
|
||||||
file->fd = 0;
|
file->fd = 0;
|
||||||
file->length = 0;
|
file->length = 0;
|
||||||
file->memroy = NULL;
|
file->memory = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
file->length = newSize;
|
file->length = newSize;
|
||||||
file->memroy = newMem;
|
file->memory = newMem;
|
||||||
return newMem;
|
return newMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_fileDelete(char * fileName) {
|
void sys_fileDelete(char * fileName) {
|
||||||
unlink(fileName);
|
unlink(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_fileRename(char * fileName, char * newFileName) {
|
void sys_fileRename(char * fileName, char * newFileName) {
|
||||||
link(fileName, newFileName);
|
link(fileName, newFileName);
|
||||||
unlink(fileName);
|
unlink(fileName);
|
||||||
}
|
}
|
@ -1,15 +1,15 @@
|
|||||||
#include "../cdb_sustem.h"
|
#include "../cdb_system.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
// Memory API
|
// Memory API
|
||||||
void * sus_heapAlloc(size_t bytes) {
|
void * sys_heapAlloc(size_t bytes) {
|
||||||
return malloc(bytes);
|
return malloc(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * sus_heapResize(void * memroy, size_t newBytes) {
|
void * sys_heapResize(void * memory, size_t newBytes) {
|
||||||
return realloc(memroy, newBytes);
|
return realloc(memory, newBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_heapFree(void * memroy) {
|
void sys_heapFree(void * memory) {
|
||||||
free(memroy);
|
free(memory);
|
||||||
}
|
}
|
@ -1,38 +1,38 @@
|
|||||||
#include "../cdb_sustem.h"
|
#include "../cdb_system.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
struct sus_thread_args {
|
struct sys_thread_args {
|
||||||
sus_threadProc proc;
|
sys_threadProc proc;
|
||||||
void *arg;
|
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)
|
// Linux only uses System V AMD64 ABI calling convention (source: https://en.wikipedia.org/wiki/X86_calling_conventions)
|
||||||
void *uwu_runThread(void *arg) {
|
void *uwu_runThread(void *arg) {
|
||||||
sus_thread_args *args = (sus_thread_args *) arg;
|
sys_thread_args *args = (sys_thread_args *) arg;
|
||||||
sus_threadProc proc = args->proc;
|
sys_threadProc proc = args->proc;
|
||||||
void *arg2 = args->arg;
|
void *arg2 = args->arg;
|
||||||
sus_heapFree(args);
|
sys_heapFree(args);
|
||||||
proc(arg2);
|
proc(arg2);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sus_Bool sus_threadNew(sus_threadProc proc, void *arg) {
|
sys_Bool sys_threadNew(sys_threadProc proc, void *arg) {
|
||||||
sus_thread_args *args = (sus_thread_args *) sus_heapAlloc(sizeof(sus_thread_args));
|
sys_thread_args *args = (sys_thread_args *) sys_heapAlloc(sizeof(sys_thread_args));
|
||||||
args->proc = proc;
|
args->proc = proc;
|
||||||
args->arg = arg;
|
args->arg = arg;
|
||||||
|
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
if(pthread_create(&thread, NULL, uwu_runThread, args)) {
|
if(pthread_create(&thread, NULL, uwu_runThread, args)) {
|
||||||
sus_heapFree(args);
|
sys_heapFree(args);
|
||||||
return sus_False;
|
return sys_False;
|
||||||
}else {
|
}else {
|
||||||
return sus_True;
|
return sys_True;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_threadSleep(unsigned long seconds) {
|
void sys_threadSleep(unsigned long seconds) {
|
||||||
sleep(seconds);
|
sleep(seconds);
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
#include "../cdb_sustem.h"
|
#include "../cdb_system.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
struct sus_File_impl{
|
struct sys_File_impl{
|
||||||
void * memroy;
|
void * memory;
|
||||||
HANDLE fileHandle;
|
HANDLE fileHandle;
|
||||||
HANDLE fileMapHandle;
|
HANDLE fileMapHandle;
|
||||||
};
|
};
|
||||||
@ -12,24 +12,24 @@ struct sus_File_impl{
|
|||||||
// if(fileMap == NULL || fileMap == INVALID_HANDLE_VALUE){
|
// if(fileMap == NULL || fileMap == INVALID_HANDLE_VALUE){
|
||||||
// return NULL;
|
// return NULL;
|
||||||
// }
|
// }
|
||||||
// void * memroy = MapViewOfFile(fileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
// void * memory = MapViewOfFile(fileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||||
// if(memroy == NULL){
|
// if(memory == NULL){
|
||||||
// CloseHandle(fileMap);
|
// CloseHandle(fileMap);
|
||||||
// }
|
// }
|
||||||
// return memroy;
|
// return memory;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
sys_File sys_fileOpenInMem(char * fileName, unsigned long parameter){
|
||||||
sus_File currentFile = sus_heapAlloc(sizeof(struct sus_File_impl));
|
sys_File currentFile = sys_heapAlloc(sizeof(struct sys_File_impl));
|
||||||
if(currentFile == NULL) return NULL;
|
if(currentFile == NULL) return NULL;
|
||||||
|
|
||||||
currentFile->fileHandle = CreateFileA(fileName,
|
currentFile->fileHandle = CreateFileA(fileName,
|
||||||
GENERIC_READ | GENERIC_WRITE, //Open for reading and writing
|
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
|
FILE_SHARE_READ, //It wouldn't be a good idea, if a different process wrote to the file at the same time
|
||||||
NULL,
|
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
|
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);
|
NULL);
|
||||||
if(currentFile->fileHandle == NULL || currentFile->fileHandle == INVALID_HANDLE_VALUE){
|
if(currentFile->fileHandle == NULL || currentFile->fileHandle == INVALID_HANDLE_VALUE){
|
||||||
//debug
|
//debug
|
||||||
@ -39,7 +39,7 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
|||||||
}
|
}
|
||||||
//void * currentAdress = internal_fileOpeninMem(currentFile);
|
//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(GetFileSize(currentFile->fileHandle, NULL) == 0){
|
||||||
if(!WriteFile(currentFile->fileHandle, "", sizeof(""), NULL, NULL)){
|
if(!WriteFile(currentFile->fileHandle, "", sizeof(""), NULL, NULL)){
|
||||||
goto cleanup2;
|
goto cleanup2;
|
||||||
@ -51,8 +51,8 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
|||||||
//return NULL;
|
//return NULL;
|
||||||
goto cleanup2;
|
goto cleanup2;
|
||||||
}
|
}
|
||||||
currentFile->memroy = MapViewOfFile(currentFile->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
currentFile->memory = MapViewOfFile(currentFile->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||||
if(currentFile->memroy == NULL){
|
if(currentFile->memory == NULL){
|
||||||
goto cleanup3;
|
goto cleanup3;
|
||||||
}
|
}
|
||||||
return currentFile;
|
return currentFile;
|
||||||
@ -68,7 +68,7 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
|||||||
cleanup2:
|
cleanup2:
|
||||||
CloseHandle(currentFile->fileHandle);
|
CloseHandle(currentFile->fileHandle);
|
||||||
cleanup1:
|
cleanup1:
|
||||||
sus_heapFree(currentFile);
|
sys_heapFree(currentFile);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -113,40 +113,40 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
|||||||
// return currentAdress;
|
// return currentAdress;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void * sus_fileFileToMemroy(sus_File file){
|
void * sys_fileFileToMemory(sys_File file){
|
||||||
return file->memroy;
|
return file->memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_fileClose(sus_File file){
|
void sys_fileClose(sys_File file){
|
||||||
if(file->memroy == NULL){
|
if(file->memory == NULL){
|
||||||
FlushViewOfFile(file->memroy, 0);
|
FlushViewOfFile(file->memory, 0);
|
||||||
UnmapViewOfFile(file->memroy);
|
UnmapViewOfFile(file->memory);
|
||||||
CloseHandle(file->fileMapHandle);
|
CloseHandle(file->fileMapHandle);
|
||||||
CloseHandle(file->fileHandle);
|
CloseHandle(file->fileHandle);
|
||||||
}
|
}
|
||||||
sus_heapFree(file);
|
sys_heapFree(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_fileFlush(sus_File file){
|
void sys_fileFlush(sys_File file){
|
||||||
FlushViewOfFile(file->memroy, 0);
|
FlushViewOfFile(file->memory, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_fileRename(char * fileName, char * newFileName){
|
void sys_fileRename(char * fileName, char * newFileName){
|
||||||
MoveFile(fileName, newFileName);
|
MoveFile(fileName, newFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_fileDelete(char * fileName){
|
void sys_fileDelete(char * fileName){
|
||||||
DeleteFile(fileName);
|
DeleteFile(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
sus_Bool sus_fileExists(char * fileName){
|
sys_Bool sys_fileExists(char * fileName){
|
||||||
DWORD fileAttributes = GetFileAttributes(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){
|
void * sys_fileResize(sys_File file, signed long appendBytes){
|
||||||
FlushViewOfFile(file->memroy, 0);
|
FlushViewOfFile(file->memory, 0);
|
||||||
UnmapViewOfFile(file->memroy);
|
UnmapViewOfFile(file->memory);
|
||||||
CloseHandle(file->fileMapHandle);
|
CloseHandle(file->fileMapHandle);
|
||||||
SetFilePointer(file->fileHandle, appendBytes, NULL, FILE_END); //Very cursed Unix style...
|
SetFilePointer(file->fileHandle, appendBytes, NULL, FILE_END); //Very cursed Unix style...
|
||||||
SetEndOfFile(file->fileHandle);
|
SetEndOfFile(file->fileHandle);
|
||||||
@ -157,11 +157,11 @@ void * sus_fileResize(sus_File file, signed long appendBytes){
|
|||||||
//return NULL;
|
//return NULL;
|
||||||
goto cleanup2;
|
goto cleanup2;
|
||||||
}
|
}
|
||||||
file->memroy = MapViewOfFile(file->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
file->memory = MapViewOfFile(file->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||||
if(file->memroy == NULL){
|
if(file->memory == NULL){
|
||||||
goto cleanup3;
|
goto cleanup3;
|
||||||
}
|
}
|
||||||
return file->memroy;
|
return file->memory;
|
||||||
|
|
||||||
cleanup3:
|
cleanup3:
|
||||||
CloseHandle(file->fileMapHandle);
|
CloseHandle(file->fileMapHandle);
|
||||||
@ -169,8 +169,8 @@ void * sus_fileResize(sus_File file, signed long appendBytes){
|
|||||||
cleanup2:
|
cleanup2:
|
||||||
CloseHandle(file->fileHandle);
|
CloseHandle(file->fileHandle);
|
||||||
file->fileHandle = NULL;
|
file->fileHandle = NULL;
|
||||||
//sus_heapFree(file);
|
//sys_heapFree(file);
|
||||||
file->memroy = NULL;
|
file->memory = NULL;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
@ -1,17 +1,17 @@
|
|||||||
#include "../cdb_sustem.h"
|
#include "../cdb_system.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
// returns NULL, if there is no memroy left or an error occured
|
// returns NULL, if there is no memory left or an error occured
|
||||||
void * sus_heapAlloc(size_t bytes){
|
void * sys_heapAlloc(size_t bytes){
|
||||||
return HeapAlloc(GetProcessHeap(), 0, bytes); //generic call to the windows heapAlloc function
|
return HeapAlloc(GetProcessHeap(), 0, bytes); //generic call to the windows heapAlloc function
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns NULL, if there is no memroy left or an error occured
|
// returns NULL, if there is no memory left or an error occured
|
||||||
void * sus_heapResize(void * memroy, size_t newBytes){
|
void * sys_heapResize(void * memory, size_t newBytes){
|
||||||
return HeapReAlloc(GetProcessHeap(), 0, memroy, newBytes);
|
return HeapReAlloc(GetProcessHeap(), 0, memory, newBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// what should this function do, if an error occurse..
|
// what should this function do, if an error occurse..
|
||||||
void sus_heapFree(void * memroy){
|
void sys_heapFree(void * memory){
|
||||||
HeapFree(GetProcessHeap(), 0, memroy);
|
HeapFree(GetProcessHeap(), 0, memory);
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
#include "../cdb_sustem.h"
|
#include "../cdb_system.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
struct threadInfo{
|
struct threadInfo{
|
||||||
sus_threadProc proc;
|
sys_threadProc proc;
|
||||||
void * args;
|
void * args;
|
||||||
};
|
};
|
||||||
|
|
||||||
DWORD WINAPI threadProc(void * tiarg){
|
DWORD WINAPI threadProc(void * tiarg){
|
||||||
struct threadInfo * ti = tiarg;
|
struct threadInfo * ti = tiarg;
|
||||||
struct threadInfo currentTI = {.args = ti->args, .proc = ti->proc};
|
struct threadInfo currentTI = {.args = ti->args, .proc = ti->proc};
|
||||||
sus_heapFree(ti);
|
sys_heapFree(ti);
|
||||||
currentTI.proc(currentTI.args);
|
currentTI.proc(currentTI.args);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sus_Bool sus_threadNew(sus_threadProc proc, void * arg){
|
sys_Bool sys_threadNew(sys_threadProc proc, void * arg){
|
||||||
struct threadInfo * ti = sus_heapAlloc(sizeof(struct threadInfo));
|
struct threadInfo * ti = sys_heapAlloc(sizeof(struct threadInfo));
|
||||||
ti->proc = proc;
|
ti->proc = proc;
|
||||||
ti->args = arg;
|
ti->args = arg;
|
||||||
if(CreateThread(NULL, 0, threadProc, ti, 0, NULL) == NULL){
|
if(CreateThread(NULL, 0, threadProc, ti, 0, NULL) == NULL){
|
||||||
sus_heapFree(ti);
|
sys_heapFree(ti);
|
||||||
return sus_False;
|
return sys_False;
|
||||||
}else{
|
}else{
|
||||||
return sus_True;
|
return sys_True;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sus_threadSleep(unsigned long seconds){
|
void sys_threadSleep(unsigned long seconds){
|
||||||
Sleep(seconds * 1000);
|
Sleep(seconds * 1000);
|
||||||
}
|
}
|
45
cdb_sustem.h
45
cdb_sustem.h
@ -1,45 +0,0 @@
|
|||||||
//TODO finland up
|
|
||||||
|
|
||||||
//#include <stddef.h>
|
|
||||||
|
|
||||||
// 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 <stddef.h>
|
|
||||||
|
|
||||||
//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);
|
|
@ -2,4 +2,4 @@
|
|||||||
if [ ! -d run ]; then
|
if [ ! -d run ]; then
|
||||||
mkdir run
|
mkdir run
|
||||||
fi
|
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
|
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
|
@ -8,7 +8,7 @@ int main() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * memory = fp_fileToMemroy(file);
|
char * memory = fp_fileToMemory(file);
|
||||||
memory[0] = 'a';
|
memory[0] = 'a';
|
||||||
memory[511] = 'b';
|
memory[511] = 'b';
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ int main() {
|
|||||||
|
|
||||||
printf("Init\n");
|
printf("Init\n");
|
||||||
fp_fileInit(file, 512);
|
fp_fileInit(file, 512);
|
||||||
memory = fp_fileToMemroy(file);
|
memory = fp_fileToMemory(file);
|
||||||
printf("%c%c%c\n", memory[0],memory[511],memory[1023]);
|
printf("%c%c%c\n", memory[0],memory[511],memory[1023]);
|
||||||
|
|
||||||
fp_fileClose(file);
|
fp_fileClose(file);
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
if [ ! -d run ]; then
|
if [ ! -d run ]; then
|
||||||
mkdir run
|
mkdir run
|
||||||
fi
|
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
|
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
|
@ -9,7 +9,7 @@ int main() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * memory = fp_fileToMemroy(file);
|
char * memory = fp_fileToMemory(file);
|
||||||
memory[0] = 'a';
|
memory[0] = 'a';
|
||||||
memory[511] = 'b';
|
memory[511] = 'b';
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
gcc.exe systemAbstractionTest1.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memroy.c" -o systemAbstractionTest1.exe
|
gcc.exe systemAbstractionTest1.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memory.c" -o systemAbstractionTest1.exe
|
@ -2,4 +2,4 @@
|
|||||||
if [ ! -d run ]; then
|
if [ ! -d run ]; then
|
||||||
mkdir run
|
mkdir run
|
||||||
fi
|
fi
|
||||||
gcc systemAbstractionTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/systemAbstractionTest1
|
gcc systemAbstractionTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/systemAbstractionTest1
|
@ -1,32 +1,32 @@
|
|||||||
#include "../../../System Abstraction/cdb_sustem.h"
|
#include "../../../System Abstraction/cdb_system.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
void main(){
|
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){
|
if(file == NULL){
|
||||||
printf("file is null\n");
|
printf("file is null\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * memroy = sus_fileFileToMemroy(file);
|
char * memory = sys_fileFileToMemory(file);
|
||||||
if(memroy == 0){
|
if(memory == 0){
|
||||||
printf("memroy was null\n");
|
printf("memory was null\n");
|
||||||
return;
|
return;
|
||||||
}else{
|
}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);
|
sys_fileResize(file, 2);
|
||||||
memroy = sus_fileFileToMemroy(file);
|
memory = sys_fileFileToMemory(file);
|
||||||
memroy[0] = 'a';
|
memory[0] = 'a';
|
||||||
memroy[1] = 'b';
|
memory[1] = 'b';
|
||||||
memroy[2] = 'c';
|
memory[2] = 'c';
|
||||||
memroy[3] = 'd';
|
memory[3] = 'd';
|
||||||
memroy[4] = 'e';
|
memory[4] = 'e';
|
||||||
sus_fileClose(file);
|
sys_fileClose(file);
|
||||||
|
|
||||||
file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING);
|
file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING);
|
||||||
memroy = sus_fileFileToMemroy(file);
|
memory = sys_fileFileToMemory(file);
|
||||||
memroy[0] = 'O';
|
memory[0] = 'O';
|
||||||
sus_fileClose(file);
|
sys_fileClose(file);
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
gcc.exe openNewFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memroy.c" -o systemAbstractionTest1.exe
|
gcc.exe openNewFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memory.c" -o systemAbstractionTest1.exe
|
@ -2,4 +2,4 @@
|
|||||||
if [ ! -d run ]; then
|
if [ ! -d run ]; then
|
||||||
mkdir run
|
mkdir run
|
||||||
fi
|
fi
|
||||||
gcc -g openNewFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/openNewFiletest
|
gcc -g openNewFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/openNewFiletest
|
@ -2,32 +2,32 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
void main(){
|
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){
|
if(file == NULL){
|
||||||
printf("file is null\n");
|
printf("file is null\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * memroy = sus_fileFileToMemroy(file);
|
char * memory = sys_fileFileToMemory(file);
|
||||||
if(memroy == 0){
|
if(memory == 0){
|
||||||
printf("memroy was null\n");
|
printf("memory was null\n");
|
||||||
return;
|
return;
|
||||||
}else{
|
}else{
|
||||||
printf("%c\n", memroy[0] == 0 ? 'Y' : 'N');
|
printf("%c\n", memory[0] == 0 ? 'Y' : 'N');
|
||||||
}
|
}
|
||||||
|
|
||||||
sus_fileResize(file, 4);
|
sys_fileResize(file, 4);
|
||||||
memroy = sus_fileFileToMemroy(file);
|
memory = sys_fileFileToMemory(file);
|
||||||
memroy[0] = 'a';
|
memory[0] = 'a';
|
||||||
memroy[1] = 'b';
|
memory[1] = 'b';
|
||||||
memroy[2] = 'c';
|
memory[2] = 'c';
|
||||||
memroy[3] = 'd';
|
memory[3] = 'd';
|
||||||
memroy[4] = 'e';
|
memory[4] = 'e';
|
||||||
sus_fileFlush(file);
|
sys_fileFlush(file);
|
||||||
sus_fileClose(file);
|
sys_fileClose(file);
|
||||||
file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING);
|
file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING);
|
||||||
memroy = sus_fileFileToMemroy(file);
|
memory = sys_fileFileToMemory(file);
|
||||||
memroy[0] = 'O';
|
memory[0] = 'O';
|
||||||
sus_fileFlush(file);
|
sys_fileFlush(file);
|
||||||
sus_fileClose(file);
|
sys_fileClose(file);
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
gcc.exe openTempFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memroy.c" -o openTempFiletest.exe
|
gcc.exe openTempFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memory.c" -o openTempFiletest.exe
|
@ -2,4 +2,4 @@
|
|||||||
if [ ! -d run ]; then
|
if [ ! -d run ]; then
|
||||||
mkdir run
|
mkdir run
|
||||||
fi
|
fi
|
||||||
gcc -g openTempFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/openTempFiletest
|
gcc -g openTempFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/openTempFiletest
|
@ -2,34 +2,34 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
void main(){
|
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){
|
if(file == NULL){
|
||||||
printf("file is null\n");
|
printf("file is null\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * memroy = sus_fileFileToMemroy(file);
|
char * memory = sys_fileFileToMemory(file);
|
||||||
if(memroy == 0){
|
if(memory == 0){
|
||||||
printf("memroy was null\n");
|
printf("memory was null\n");
|
||||||
return;
|
return;
|
||||||
}else{
|
}else{
|
||||||
printf("%c\n", memroy[0] == 0 ? 'Y' : 'N');
|
printf("%c\n", memory[0] == 0 ? 'Y' : 'N');
|
||||||
}
|
}
|
||||||
|
|
||||||
sus_fileResize(file, 4);
|
sys_fileResize(file, 4);
|
||||||
memroy = sus_fileFileToMemroy(file);
|
memory = sys_fileFileToMemory(file);
|
||||||
memroy[0] = 'a';
|
memory[0] = 'a';
|
||||||
memroy[1] = 'b';
|
memory[1] = 'b';
|
||||||
memroy[2] = 'c';
|
memory[2] = 'c';
|
||||||
memroy[3] = 'd';
|
memory[3] = 'd';
|
||||||
memroy[4] = 'e';
|
memory[4] = 'e';
|
||||||
sus_fileClose(file);
|
sys_fileClose(file);
|
||||||
|
|
||||||
file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING);
|
file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING);
|
||||||
if(file == NULL) {
|
if(file == NULL) {
|
||||||
printf("Second file is null\n");
|
printf("Second file is null\n");
|
||||||
}else {
|
}else {
|
||||||
printf("Second file is NOT null\n");
|
printf("Second file is NOT null\n");
|
||||||
sus_fileClose(file);
|
sys_fileClose(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,32 +2,32 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
void main(){
|
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){
|
if(file == NULL){
|
||||||
printf("file is null");
|
printf("file is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * memroy = sus_fileFileToMemroy(file);
|
char * memory = sys_fileFileToMemory(file);
|
||||||
if(memroy == 0){
|
if(memory == 0){
|
||||||
printf("memroy was null\n");
|
printf("memory was null\n");
|
||||||
return;
|
return;
|
||||||
}else{
|
}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);
|
sys_fileResize(file, 2);
|
||||||
memroy = sus_fileFileToMemroy(file);
|
memory = sys_fileFileToMemory(file);
|
||||||
memroy[0] = 'a';
|
memory[0] = 'a';
|
||||||
memroy[1] = 'b';
|
memory[1] = 'b';
|
||||||
memroy[2] = 'c';
|
memory[2] = 'c';
|
||||||
memroy[3] = 'd';
|
memory[3] = 'd';
|
||||||
memroy[4] = 'e';
|
memory[4] = 'e';
|
||||||
sus_fileFlush(file);
|
sys_fileFlush(file);
|
||||||
sus_fileClose(file);
|
sys_fileClose(file);
|
||||||
file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING);
|
file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING);
|
||||||
memroy = sus_fileFileToMemroy(file);
|
memory = sys_fileFileToMemory(file);
|
||||||
memroy[0] = 'O';
|
memory[0] = 'O';
|
||||||
sus_fileFlush(file);
|
sys_fileFlush(file);
|
||||||
sus_fileClose(file);
|
sys_fileClose(file);
|
||||||
}
|
}
|
@ -2,4 +2,4 @@
|
|||||||
if [ ! -d run ]; then
|
if [ ! -d run ]; then
|
||||||
mkdir run
|
mkdir run
|
||||||
fi
|
fi
|
||||||
gcc -g renameFileTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/renameFileTest
|
gcc -g renameFileTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/renameFileTest
|
@ -2,5 +2,5 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
sus_fileRename("testfile.txt", "renamedtestfile.txt");
|
sys_fileRename("testfile.txt", "renamedtestfile.txt");
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
gcc.exe threadsTest.c "../../../System Abstraction/win32/cdb_thread.c" "../../../System Abstraction/win32/cdb_memroy.c" -o threadTests.exe
|
gcc.exe threadsTest.c "../../../System Abstraction/win32/cdb_thread.c" "../../../System Abstraction/win32/cdb_memory.c" -o threadTests.exe
|
@ -2,4 +2,4 @@
|
|||||||
if [ ! -d run ]; then
|
if [ ! -d run ]; then
|
||||||
mkdir run
|
mkdir run
|
||||||
fi
|
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
|
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
|
@ -3,14 +3,14 @@
|
|||||||
|
|
||||||
__attribute__ ((sysv_abi)) void testProc(void * arg){
|
__attribute__ ((sysv_abi)) void testProc(void * arg){
|
||||||
printf("in testProc ... Going to sleep, %i\n", *(int *)arg);
|
printf("in testProc ... Going to sleep, %i\n", *(int *)arg);
|
||||||
sus_threadSleep(5);
|
sys_threadSleep(5);
|
||||||
printf("after sleeping in testProc\n");
|
printf("after sleeping in testProc\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
int amogus = 1234567;
|
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");
|
printf("Going to sleep in main Thread\n");
|
||||||
sus_threadSleep(10);
|
sys_threadSleep(10);
|
||||||
printf("After sleeping in main Thread\n");
|
printf("After sleeping in main Thread\n");
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user